2014-05-15 05:24:49 +04:00
|
|
|
import ajax from 'ghost/utils/ajax';
|
2014-03-10 07:44:08 +04:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
|
|
|
|
|
|
|
var SignupRoute = Ember.Route.extend(styleBody, {
|
2014-05-15 05:24:49 +04:00
|
|
|
classNames: ['ghost-signup'],
|
|
|
|
|
|
|
|
name: null,
|
|
|
|
email: null,
|
|
|
|
password: null,
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
signup: function () {
|
|
|
|
var self = this,
|
|
|
|
controller = this.get('controller'),
|
|
|
|
data = controller.getProperties('name', 'email', 'password');
|
|
|
|
|
|
|
|
// TODO: Validate data
|
|
|
|
|
|
|
|
if (data.name && data.email && data.password) {
|
|
|
|
ajax({
|
|
|
|
url: '/ghost/signup/',
|
|
|
|
type: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': this.get('csrf')
|
|
|
|
},
|
|
|
|
data: data
|
|
|
|
}).then(function (resp) {
|
|
|
|
if (resp && resp.userData) {
|
2014-05-09 09:00:10 +04:00
|
|
|
self.store.pushPayload({ users: [resp.userData]});
|
|
|
|
self.store.find('user', resp.userData.id).then(function (user) {
|
|
|
|
self.send('signedIn', user);
|
|
|
|
self.notifications.clear();
|
|
|
|
self.transitionTo('posts');
|
|
|
|
});
|
2014-05-15 05:24:49 +04:00
|
|
|
} else {
|
|
|
|
self.transitionTo('signin');
|
|
|
|
}
|
|
|
|
}, function (resp) {
|
|
|
|
self.notifications.showAPIError(resp);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.notifications.showError('Must provide name, email and password');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-10 07:44:08 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default SignupRoute;
|