2015-03-29 20:10:53 +02:00
|
|
|
/* global md5 */
|
|
|
|
import Ember from 'ember';
|
2015-05-27 15:10:47 -05:00
|
|
|
import {request as ajax} from 'ic-ajax';
|
2015-03-29 20:10:53 +02:00
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
|
|
|
|
2015-05-27 15:10:47 -05:00
|
|
|
export default Ember.Controller.extend(ValidationEngine, {
|
2015-03-29 20:10:53 +02:00
|
|
|
size: 90,
|
|
|
|
blogTitle: null,
|
|
|
|
name: null,
|
|
|
|
email: '',
|
|
|
|
password: null,
|
|
|
|
image: null,
|
|
|
|
submitting: false,
|
|
|
|
|
2015-05-27 15:10:47 -05:00
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
|
|
notifications: Ember.inject.service(),
|
2015-05-28 08:58:52 -05:00
|
|
|
application: Ember.inject.controller(),
|
2015-05-27 15:10:47 -05:00
|
|
|
|
2015-03-29 20:10:53 +02:00
|
|
|
gravatarUrl: Ember.computed('email', function () {
|
|
|
|
var email = this.get('email'),
|
|
|
|
size = this.get('size');
|
|
|
|
|
|
|
|
return 'http://www.gravatar.com/avatar/' + md5(email) + '?s=' + size + '&d=blank';
|
|
|
|
}),
|
|
|
|
|
|
|
|
userImage: Ember.computed('gravatarUrl', function () {
|
|
|
|
return this.get('image') || this.get('gravatarUrl');
|
|
|
|
}),
|
|
|
|
|
|
|
|
userImageBackground: Ember.computed('userImage', function () {
|
|
|
|
return 'background-image: url(' + this.get('userImage') + ')';
|
|
|
|
}),
|
|
|
|
|
2015-06-06 22:19:19 -05:00
|
|
|
invalidMessage: 'The password fairy does not approve',
|
|
|
|
|
2015-03-29 20:10:53 +02:00
|
|
|
// ValidationEngine settings
|
|
|
|
validationType: 'setup',
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
setup: function () {
|
|
|
|
var self = this,
|
2015-06-06 22:19:19 -05:00
|
|
|
data = self.getProperties('blogTitle', 'name', 'email', 'password'),
|
|
|
|
notifications = this.get('notifications');
|
2015-03-29 20:10:53 +02:00
|
|
|
|
|
|
|
this.toggleProperty('submitting');
|
2015-06-06 22:19:19 -05:00
|
|
|
this.validate().then(function () {
|
|
|
|
self.set('showError', false);
|
2015-03-29 20:10:53 +02:00
|
|
|
ajax({
|
|
|
|
url: self.get('ghostPaths.url').api('authentication', 'setup'),
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
setup: [{
|
|
|
|
name: data.name,
|
|
|
|
email: data.email,
|
|
|
|
password: data.password,
|
|
|
|
blogTitle: data.blogTitle
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}).then(function () {
|
2015-05-28 08:58:52 -05:00
|
|
|
// Don't call the success handler, otherwise we will be redirected to admin
|
|
|
|
self.get('application').set('skipAuthSuccessHandler', true);
|
|
|
|
|
2015-03-29 20:10:53 +02:00
|
|
|
self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
|
|
|
|
identification: self.get('email'),
|
|
|
|
password: self.get('password')
|
2015-05-28 08:58:52 -05:00
|
|
|
}).then(function () {
|
|
|
|
self.set('password', '');
|
|
|
|
self.transitionToRoute('setup.three');
|
2015-03-29 20:10:53 +02:00
|
|
|
});
|
|
|
|
}).catch(function (resp) {
|
|
|
|
self.toggleProperty('submitting');
|
2015-05-27 15:10:47 -05:00
|
|
|
notifications.showAPIError(resp);
|
2015-03-29 20:10:53 +02:00
|
|
|
});
|
2015-06-06 22:19:19 -05:00
|
|
|
}).catch(function () {
|
2015-03-29 20:10:53 +02:00
|
|
|
self.toggleProperty('submitting');
|
2015-06-06 22:19:19 -05:00
|
|
|
self.set('showError', true);
|
2015-03-29 20:10:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|