diff --git a/core/client/app/controllers/signup.js b/core/client/app/controllers/signup.js
index 794222305d..834ecdf4a2 100644
--- a/core/client/app/controllers/signup.js
+++ b/core/client/app/controllers/signup.js
@@ -8,15 +8,43 @@ export default Ember.Controller.extend(ValidationEngine, {
submitting: false,
flowErrors: '',
+ image: null,
+ validEmail: '',
ghostPaths: Ember.inject.service('ghost-paths'),
+ config: Ember.inject.service(),
notifications: Ember.inject.service(),
+ sendImage: function () {
+ var self = this,
+ image = this.get('image');
+
+ this.get('session.user').then(function (user) {
+ return new Ember.RSVP.Promise(function (resolve, reject) {
+ image.formData = {};
+ image.submit()
+ .success(function (response) {
+ user.image = response;
+ ajax({
+ url: self.get('ghostPaths.url').api('users', user.id.toString()),
+ type: 'PUT',
+ data: {
+ users: [user]
+ }
+ }).then(resolve).catch(reject);
+ })
+ .error(reject);
+ });
+ });
+ },
+
actions: {
signup: function () {
var self = this,
model = this.get('model'),
data = model.getProperties('name', 'email', 'password', 'token'),
+ image = this.get('image'),
+
notifications = this.get('notifications');
this.set('flowErrors', '');
@@ -40,6 +68,12 @@ export default Ember.Controller.extend(ValidationEngine, {
self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
identification: self.get('model.email'),
password: self.get('model.password')
+ }).then(function () {
+ if (image) {
+ self.sendImage();
+ }
+ }).catch(function (resp) {
+ notifications.showAPIError(resp);
});
}).catch(function (resp) {
self.toggleProperty('submitting');
@@ -52,6 +86,16 @@ export default Ember.Controller.extend(ValidationEngine, {
}).catch(function () {
self.set('flowErrors', 'Please fill out the form to complete your sign-up');
});
+ },
+ setImage: function (image) {
+ this.set('image', image);
+ },
+ handleEmail: function () {
+ var self = this;
+
+ this.validate({property: 'email'}).then(function () {
+ self.set('validEmail', self.get('email'));
+ });
}
}
});
diff --git a/core/client/app/templates/signup.hbs b/core/client/app/templates/signup.hbs
index 49a86ff053..934b8d12af 100644
--- a/core/client/app/templates/signup.hbs
+++ b/core/client/app/templates/signup.hbs
@@ -11,17 +11,11 @@
-
+ {{gh-profile-image fileStorage=config.fileStorage email=validEmail setImage="setImage"}}
{{#gh-form-group errors=model.errors property="email"}}
- {{gh-input type="email" name="email" placeholder="Eg. john@example.com" class="gh-input" enter=(action "signup") disabled=true autocorrect="off" value=model.email focusOut=(action "validate" "email")}}
+ {{gh-input type="email" name="email" placeholder="Eg. john@example.com" class="gh-input" enter=(action "signup") disabled=true autocorrect="off" value=model.email focusOut=(action "handleEmail")}}
{{gh-error-message errors=model.errors property="email"}}
{{/gh-form-group}}