1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/controllers/signup.js
Jason Williams 78685a3ade Fixup validation engine to handle lack of proxying
Closes #4766
- Adjust ValidationEngine so it no longer assumes the properties
  it is validating are proxies via ObjectController.
- Fixup controllers, templates, and routes to use models where
  data needs to be validated.
2015-01-12 03:27:47 +00:00

50 lines
1.7 KiB
JavaScript

import ajax from 'ghost/utils/ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';
var SignupController = Ember.Controller.extend(ValidationEngine, {
submitting: false,
// ValidationEngine settings
validationType: 'signup',
actions: {
signup: function () {
var self = this,
model = this.get('model'),
data = model.getProperties('name', 'email', 'password', 'token');
self.notifications.closePassive();
this.toggleProperty('submitting');
this.validate({format: false}).then(function () {
ajax({
url: self.get('ghostPaths.url').api('authentication', 'invitation'),
type: 'POST',
dataType: 'json',
data: {
invitation: [{
name: data.name,
email: data.email,
password: data.password,
token: data.token
}]
}
}).then(function () {
self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
identification: self.get('model.email'),
password: self.get('model.password')
});
}, function (resp) {
self.toggleProperty('submitting');
self.notifications.showAPIError(resp);
});
}, function (errors) {
self.toggleProperty('submitting');
self.notifications.showErrors(errors);
});
}
}
});
export default SignupController;