Ghost/core/client/controllers/signup.js
Fabian Becker 1af5eb6248 Close notifications on user action properly.
fixes #3105, refs #3012
- Add additional closeAll() calls where users interact with data
2014-06-25 16:56:09 +00:00

53 lines
1.8 KiB
JavaScript

import ajax from 'ghost/utils/ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';
var SignupController = Ember.ObjectController.extend(ValidationEngine, {
name: null,
email: null,
password: null,
submitting: false,
// ValidationEngine settings
validationType: 'signup',
actions: {
signup: function () {
var self = this;
// @TODO This should call closePassive() to only close passive notifications
self.notifications.closeAll();
this.toggleProperty('submitting');
this.validate({ format: false }).then(function () {
ajax({
url: self.get('ghostPaths').adminUrl('signup'),
type: 'POST',
headers: {
'X-CSRF-Token': self.get('csrf')
},
data: self.getProperties('name', 'email', 'password')
}).then(function (resp) {
self.toggleProperty('submitting');
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.transitionToRoute('posts');
});
} else {
self.transitionToRoute('signin');
}
}, function (resp) {
self.toggleProperty('submitting');
self.notifications.showAPIError(resp);
});
}, function (errors) {
self.toggleProperty('submitting');
self.notifications.showErrors(errors);
});
}
}
});
export default SignupController;