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-25 16:12:48 +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-25 16:12:48 +04:00
|
|
|
blogTitle: null,
|
|
|
|
name: null,
|
|
|
|
email: null,
|
|
|
|
password: null,
|
|
|
|
submitting: false,
|
|
|
|
|
|
|
|
// ValidationEngine settings
|
|
|
|
validationType: 'setup',
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
setup: function () {
|
2014-07-11 16:17:09 +04:00
|
|
|
var self = this,
|
|
|
|
data = self.getProperties('blogTitle', 'name', 'email', 'password');
|
2014-06-25 16:12:48 +04:00
|
|
|
|
2014-06-30 01:45:03 +04:00
|
|
|
self.notifications.closePassive();
|
2014-06-25 16:12:48 +04:00
|
|
|
|
|
|
|
this.toggleProperty('submitting');
|
2014-10-25 01:09:50 +04:00
|
|
|
this.validate({format: false}).then(function () {
|
2014-06-25 16:12:48 +04:00
|
|
|
ajax({
|
2014-07-13 08:01:26 +04:00
|
|
|
url: self.get('ghostPaths.url').api('authentication', 'setup'),
|
2014-06-25 16:12:48 +04:00
|
|
|
type: 'POST',
|
2014-07-11 16:17:09 +04:00
|
|
|
data: {
|
|
|
|
setup: [{
|
|
|
|
name: data.name,
|
|
|
|
email: data.email,
|
|
|
|
password: data.password,
|
|
|
|
blogTitle: data.blogTitle
|
|
|
|
}]
|
|
|
|
}
|
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-06-30 17:34:36 +04:00
|
|
|
identification: self.get('email'),
|
|
|
|
password: self.get('password')
|
|
|
|
});
|
2014-10-02 19:12:54 +04:00
|
|
|
}).catch(function (resp) {
|
2014-06-25 16:12:48 +04:00
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showAPIError(resp);
|
|
|
|
});
|
2014-10-02 19:12:54 +04:00
|
|
|
}).catch(function (errors) {
|
2014-06-25 16:12:48 +04:00
|
|
|
self.toggleProperty('submitting');
|
|
|
|
self.notifications.showErrors(errors);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|