ducky/web

Paddy 2015-07-07 Parent:6b7037b4cbe7

20:13d27b50d79e Go to Latest

ducky/web/src/models/profiles.js

Remove local-storage wrapper, minor updates to Me model. No longer use our local-storage helper (remove it entirely), as we're no longer going to be a Chrome app. So let's just always rely on localStorage. Update our Me URL to use the nginx-fronted URL. Add an email property to our Me model, to keep track of the email we logged in with. This is mostly used for setting up our subscription, and should be deprecated in the future.

History
paddy@13 1 import Collection from 'ampersand-rest-collection'
paddy@0 2 import Profile from './profile'
paddy@0 3 import config from '../config'
paddy@0 4 import isObject from 'lodash.isobject'
paddy@13 5 import refresh from '../helpers/oauth-refresh'
paddy@13 6 import app from 'ampersand-app'
paddy@0 7
paddy@0 8 export default Collection.extend({
paddy@0 9 model: Profile,
paddy@19 10 url: config.urlBase + '/auth/profiles',
paddy@13 11 ajaxConfig () {
paddy@13 12 return {
paddy@13 13 headers: {
paddy@13 14 'Authorization': 'Bearer '+app.me.access_token,
paddy@13 15 'Accept': 'application/json',
paddy@13 16 }
paddy@0 17 }
paddy@0 18 },
paddy@0 19
paddy@13 20 sync: refresh.Sync,
paddy@13 21
paddy@0 22 register (email, passphrase) {
paddy@0 23 let options = {
paddy@0 24 data: JSON.stringify({
paddy@0 25 'email': email,
paddy@0 26 'passphrase': passphrase,
paddy@0 27 })
paddy@0 28 }
paddy@0 29 let moc = this
paddy@0 30 options.success = function(resp) {
paddy@0 31 if (!resp.profiles || resp.profiles.length < 1) {
paddy@0 32 return false
paddy@0 33 }
paddy@0 34 let serverAttrs = moc.parse(resp.profiles[0], options)
paddy@0 35 if (options.wait) serverAttrs = assign({}, serverAttrs)
paddy@0 36 if (isObject(serverAttrs) && !moc.add(serverAttrs, options)) {
paddy@0 37 return false
paddy@0 38 }
paddy@0 39 moc.trigger('sync', moc, resp, options)
paddy@0 40 }
paddy@0 41 options.error = function(resp) {
paddy@0 42 moc.trigger('error', moc, resp, options)
paddy@0 43 }
paddy@19 44 let sync = refresh.Sync('create', moc, options)
paddy@0 45 return sync
paddy@0 46 },
paddy@0 47 })