From 1631cb8066c1a4846622b0ee0e78648ac1d7b305 Mon Sep 17 00:00:00 2001 From: cobbspur Date: Mon, 10 Aug 2015 18:45:50 +0100 Subject: [PATCH] Fix errors for setup and signup refs #5635 - adds enter action to signup fields - adds validation text errors --- core/client/app/controllers/setup/two.js | 11 ++++++++--- core/client/app/controllers/signup.js | 14 +++++++++----- core/client/app/templates/setup/two.hbs | 3 ++- core/client/app/templates/signup.hbs | 9 +++++---- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/core/client/app/controllers/setup/two.js b/core/client/app/controllers/setup/two.js index c506e723e1..4daa93da04 100644 --- a/core/client/app/controllers/setup/two.js +++ b/core/client/app/controllers/setup/two.js @@ -12,6 +12,7 @@ export default Ember.Controller.extend(ValidationEngine, { image: null, blogCreated: false, submitting: false, + flowErrors: '', ghostPaths: Ember.inject.service('ghost-paths'), notifications: Ember.inject.service(), @@ -56,9 +57,9 @@ export default Ember.Controller.extend(ValidationEngine, { method = this.get('blogCreated') ? 'PUT' : 'POST'; this.toggleProperty('submitting'); + this.set('flowErrors', ''); this.validate().then(function () { - self.set('showError', false); ajax({ url: self.get('ghostPaths.url').api('authentication', 'setup'), type: method, @@ -96,11 +97,15 @@ export default Ember.Controller.extend(ValidationEngine, { }); }).catch(function (resp) { self.toggleProperty('submitting'); - notifications.showAPIError(resp); + if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.errors) { + self.set('flowErrors', resp.jqXHR.responseJSON.errors[0].message); + } else { + notifications.showAPIError(resp); + } }); }).catch(function () { self.toggleProperty('submitting'); - self.set('showError', true); + self.set('flowErrors', 'Please fill out the form to setup your blog.'); }); }, setImage: function (image) { diff --git a/core/client/app/controllers/signup.js b/core/client/app/controllers/signup.js index 0f360786a2..f9f81d5964 100644 --- a/core/client/app/controllers/signup.js +++ b/core/client/app/controllers/signup.js @@ -7,6 +7,7 @@ export default Ember.Controller.extend(ValidationEngine, { validationType: 'signup', submitting: false, + flowErrors: '', ghostPaths: Ember.inject.service('ghost-paths'), notifications: Ember.inject.service(), @@ -18,6 +19,7 @@ export default Ember.Controller.extend(ValidationEngine, { data = model.getProperties('name', 'email', 'password', 'token'), notifications = this.get('notifications'); + this.set('flowErrors', ''); notifications.closeNotifications(); this.validate().then(function () { @@ -41,12 +43,14 @@ export default Ember.Controller.extend(ValidationEngine, { }); }).catch(function (resp) { self.toggleProperty('submitting'); - notifications.showAPIError(resp); + if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.errors) { + self.set('flowErrors', 'That email address is already in use.'); + } else { + notifications.showAPIError(resp); + } }); - }).catch(function (error) { - if (error) { - notifications.showAPIError(error); - } + }).catch(function () { + self.set('flowErrors', 'Please fill out the form to complete your sign-up'); }); } } diff --git a/core/client/app/templates/setup/two.hbs b/core/client/app/templates/setup/two.hbs index ba333643af..2c9d1bb2e3 100644 --- a/core/client/app/templates/setup/two.hbs +++ b/core/client/app/templates/setup/two.hbs @@ -40,4 +40,5 @@ {{#gh-spin-button type="button" class="btn btn-green btn-lg btn-block" action="setup" submitting=submitting autoWidth=false}} Last step: Invite your team {{/gh-spin-button}} -

{{#if showError}}{{invalidMessage}}{{/if}}

+ +

{{{flowErrors}}}

diff --git a/core/client/app/templates/signup.hbs b/core/client/app/templates/signup.hbs index 346ddaa7c0..b6a5e35eb6 100644 --- a/core/client/app/templates/signup.hbs +++ b/core/client/app/templates/signup.hbs @@ -21,21 +21,21 @@ {{#gh-form-group errors=model.errors property="email"}} - {{gh-input type="email" name="email" placeholder="Eg. john@example.com" class="gh-input" autofocus="autofocus" 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") autofocus="autofocus" autocorrect="off" value=model.email focusOut=(action "validate" "email")}} {{gh-error-message errors=model.errors property="email"}} {{/gh-form-group}} {{#gh-form-group errors=model.errors property="name"}} - {{gh-input type="text" name="name" placeholder="Eg. John H. Watson" class="gh-input" autofocus="autofocus" autocorrect="off" value=model.name focusOut=(action "validate" "name")}} + {{gh-input type="text" name="name" placeholder="Eg. John H. Watson" class="gh-input" enter=(action "signup") autofocus="autofocus" autocorrect="off" value=model.name focusOut=(action "validate" "name")}} {{gh-error-message errors=model.errors property="name"}} {{/gh-form-group}} {{#gh-form-group errors=model.errors property="password"}} - {{input class="gh-input" type="password" name="password" autofocus="autofocus" autocorrect="off" value=model.password focusOut=(action "validate" "password")}} + {{input class="gh-input" type="password" name="password" autofocus="autofocus" enter=(action "signup") autocorrect="off" value=model.password focusOut=(action "validate" "password")}}
@@ -48,7 +48,8 @@ {{/gh-form-group}} - {{gh-spin-button type="submit" class="btn btn-green btn-lg btn-block" action="signup" submitting=submitting autoWidth=false}} + {{gh-spin-button type="submit" class="btn btn-green btn-lg btn-block" action="signup" submitting=submitting buttonText="Create Account" autoWidth=false}} +

{{{flowErrors}}}