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