Ghost/ghost/admin/routes/signup.js
Maurice Williams 2afc1ff04f Re-implementing the loading indicator for the Ember admin
closes #2855 , closes #2848
- New  mixin that utilizes NProgress for displaying a loading indictor for all routes who's model issue a "loading" event (aka: when requesting data from the server during a route change).
- Also removing (the now unnecessary) "loading" template.
2014-06-23 10:01:33 -04:00

50 lines
1.7 KiB
JavaScript

import ajax from 'ghost/utils/ajax';
import styleBody from 'ghost/mixins/style-body';
import loadingIndicator from 'ghost/mixins/loading-indicator';
var SignupRoute = Ember.Route.extend(styleBody, loadingIndicator, {
classNames: ['ghost-signup'],
name: null,
email: null,
password: null,
actions: {
signup: function () {
var self = this,
controller = this.get('controller'),
data = controller.getProperties('name', 'email', 'password');
// TODO: Validate data
if (data.name && data.email && data.password) {
ajax({
url: '/ghost/signup/',
type: 'POST',
headers: {
'X-CSRF-Token': this.get('csrf')
},
data: data
}).then(function (resp) {
if (resp && resp.userData) {
self.store.pushPayload({ users: [resp.userData]});
self.store.find('user', resp.userData.id).then(function (user) {
self.send('signedIn', user);
self.notifications.clear();
self.transitionTo('posts');
});
} else {
self.transitionTo('signin');
}
}, function (resp) {
self.notifications.showAPIError(resp);
});
} else {
this.notifications.showError('Must provide name, email and password');
}
}
}
});
export default SignupRoute;