ducky/web

Paddy 2015-05-03 Child:d51e39bf909c

0:99a43a6d1d30 Go to Latest

ducky/web/src/models/profiles.js

First commit. Setup project structure, start getting our registration flow set up. At this point, it runs successfully locally, assuming the auth server is running locally at slightly.local:8080. So, uh... on my computer. Also, we currently have the Register button (on the register page) disabled always, because we still need to hook up form validation and set the this.state.valid property. If that property is set to true, then the button is enabled again. Still to do: validation, logging in. Then what we have written works, minus some configuration stuff that still needs to be figured out.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/models/profiles.js	Sun May 03 23:25:12 2015 -0400
     1.3 @@ -0,0 +1,41 @@
     1.4 +import Collection from 'ampersand-collection'
     1.5 +import Sync from 'ampersand-sync'
     1.6 +import Profile from './profile'
     1.7 +import config from '../config'
     1.8 +import isObject from 'lodash.isobject'
     1.9 +
    1.10 +export default Collection.extend({
    1.11 +  model: Profile,
    1.12 +  url: config.urlBase + '/profiles',
    1.13 +  ajaxConfig: {
    1.14 +    headers: {
    1.15 +      'Content-Type': 'application/json',
    1.16 +    }
    1.17 +  },
    1.18 +
    1.19 +  register (email, passphrase) {
    1.20 +    let options = {
    1.21 +      data: JSON.stringify({
    1.22 +        'email': email,
    1.23 +        'passphrase': passphrase,
    1.24 +      })
    1.25 +    }
    1.26 +    let moc = this
    1.27 +    options.success = function(resp) {
    1.28 +      if (!resp.profiles || resp.profiles.length < 1) {
    1.29 +        return false
    1.30 +      }
    1.31 +      let serverAttrs = moc.parse(resp.profiles[0], options)
    1.32 +      if (options.wait) serverAttrs = assign({}, serverAttrs)
    1.33 +      if (isObject(serverAttrs) && !moc.add(serverAttrs, options)) {
    1.34 +        return false
    1.35 +      }
    1.36 +      moc.trigger('sync', moc, resp, options)
    1.37 +    }
    1.38 +    options.error = function(resp) {
    1.39 +      moc.trigger('error', moc, resp, options)
    1.40 +    }
    1.41 +    let sync = Sync('create', moc, options)
    1.42 +    return sync
    1.43 +  },
    1.44 +})