2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2015-05-26 19:41:12 -05:00
|
|
|
import {request as ajax} from 'ic-ajax';
|
2014-06-23 19:47:51 -05:00
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
|
|
|
|
2015-05-26 19:41:12 -05:00
|
|
|
export default Ember.Controller.extend(ValidationEngine, {
|
2014-06-23 19:47:51 -05:00
|
|
|
// ValidationEngine settings
|
|
|
|
validationType: 'signup',
|
|
|
|
|
2015-05-25 21:10:50 -05:00
|
|
|
submitting: false,
|
|
|
|
|
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
|
|
notifications: Ember.inject.service(),
|
|
|
|
|
2014-06-23 19:47:51 -05:00
|
|
|
actions: {
|
|
|
|
signup: function () {
|
2014-07-03 17:06:07 +02:00
|
|
|
var self = this,
|
2015-01-12 03:15:13 +00:00
|
|
|
model = this.get('model'),
|
2015-05-25 21:10:50 -05:00
|
|
|
data = model.getProperties('name', 'email', 'password', 'token'),
|
|
|
|
notifications = this.get('notifications');
|
2014-06-23 19:47:51 -05:00
|
|
|
|
2015-05-25 21:10:50 -05:00
|
|
|
notifications.closePassive();
|
2014-06-25 16:56:09 +00:00
|
|
|
|
2014-06-23 19:47:51 -05:00
|
|
|
this.toggleProperty('submitting');
|
2014-10-24 21:09:50 +00:00
|
|
|
this.validate({format: false}).then(function () {
|
2014-06-23 19:47:51 -05:00
|
|
|
ajax({
|
2014-07-13 00:01:26 -04:00
|
|
|
url: self.get('ghostPaths.url').api('authentication', 'invitation'),
|
2014-06-23 19:47:51 -05:00
|
|
|
type: 'POST',
|
2014-07-03 17:06:07 +02:00
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
invitation: [{
|
|
|
|
name: data.name,
|
|
|
|
email: data.email,
|
|
|
|
password: data.password,
|
|
|
|
token: data.token
|
|
|
|
}]
|
|
|
|
}
|
2014-06-30 15:34:36 +02:00
|
|
|
}).then(function () {
|
2014-07-25 15:38:13 +02:00
|
|
|
self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
|
2014-12-29 21:11:24 -05:00
|
|
|
identification: self.get('model.email'),
|
|
|
|
password: self.get('model.password')
|
2014-06-30 15:34:36 +02:00
|
|
|
});
|
2015-05-27 15:10:47 -05:00
|
|
|
}).catch(function (resp) {
|
2014-06-23 19:47:51 -05:00
|
|
|
self.toggleProperty('submitting');
|
2015-05-25 21:10:50 -05:00
|
|
|
notifications.showAPIError(resp);
|
2014-06-23 19:47:51 -05:00
|
|
|
});
|
2015-05-27 15:10:47 -05:00
|
|
|
}).catch(function (errors) {
|
2014-06-23 19:47:51 -05:00
|
|
|
self.toggleProperty('submitting');
|
2015-05-25 21:10:50 -05:00
|
|
|
notifications.showErrors(errors);
|
2014-06-23 19:47:51 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|