2014-06-24 04:47:51 +04:00
|
|
|
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,
|
2014-07-03 19:06:07 +04:00
|
|
|
token: null,
|
2014-06-24 04:47:51 +04:00
|
|
|
submitting: false,
|
|
|
|
|
|
|
|
// ValidationEngine settings
|
|
|
|
validationType: 'signup',
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
signup: function () {
|
2014-07-03 19:06:07 +04:00
|
|
|
var self = this,
|
|
|
|
data = self.getProperties('name', 'email', 'password', 'token');
|
2014-06-24 04:47:51 +04:00
|
|
|
|
2014-06-30 01:45:03 +04:00
|
|
|
self.notifications.closePassive();
|
2014-06-25 20:56:09 +04:00
|
|
|
|
2014-06-24 04:47:51 +04:00
|
|
|
this.toggleProperty('submitting');
|
|
|
|
this.validate({ format: false }).then(function () {
|
|
|
|
ajax({
|
2014-07-13 08:01:26 +04:00
|
|
|
url: self.get('ghostPaths.url').api('authentication', 'invitation'),
|
2014-06-24 04:47:51 +04:00
|
|
|
type: 'POST',
|
2014-07-03 19:06:07 +04:00
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
invitation: [{
|
|
|
|
name: data.name,
|
|
|
|
email: data.email,
|
|
|
|
password: data.password,
|
|
|
|
token: data.token
|
|
|
|
}]
|
|
|
|
}
|
2014-06-30 17:34:36 +04:00
|
|
|
}).then(function () {
|
|
|
|
self.get('session').authenticate('ember-simple-auth-authenticator:oauth2-password-grant', {
|
|
|
|
identification: self.get('email'),
|
|
|
|
password: self.get('password')
|
|
|
|
}).then(function () {
|
2014-07-01 19:58:26 +04:00
|
|
|
self.send('signedIn');
|
|
|
|
self.transitionToRoute(Ember.SimpleAuth.routeAfterAuthentication);
|
2014-06-30 17:34:36 +04:00
|
|
|
});
|
2014-06-24 04:47:51 +04:00
|
|
|
}, function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showAPIError(resp);
|
|
|
|
});
|
|
|
|
}, function (errors) {
|
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showErrors(errors);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SignupController;
|