Merge pull request #5085 from ErisDS/improved-forgotten

Improve the forgotten password flow
This commit is contained in:
Jason Williams 2015-04-03 13:40:16 -05:00
commit bf3693a7fa
5 changed files with 36 additions and 11 deletions

View File

@ -11,9 +11,12 @@ var ForgottenController = Ember.Controller.extend(ValidationEngine, {
actions: {
submit: function () {
var self = this,
data = self.getProperties('email');
var data = this.getProperties('email');
this.send('doForgotten', data, true);
},
doForgotten: function (data, delay) {
var self = this;
this.set('email', data.email);
this.toggleProperty('submitting');
this.validate({format: false}).then(function () {
ajax({
@ -26,7 +29,7 @@ var ForgottenController = Ember.Controller.extend(ValidationEngine, {
}
}).then(function () {
self.toggleProperty('submitting');
self.notifications.showSuccess('Please check your email for instructions.', {delayed: true});
self.notifications.showSuccess('Please check your email for instructions.', {delayed: delay});
self.set('email', '');
self.transitionToRoute('signin');
}).catch(function (resp) {

View File

@ -3,6 +3,7 @@ import ValidationEngine from 'ghost/mixins/validation-engine';
var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin, ValidationEngine, {
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
forgotten: Ember.inject.controller(),
validationType: 'signin',
@ -31,6 +32,14 @@ var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControll
}).catch(function (errors) {
self.notifications.showErrors(errors);
});
},
forgotten: function () {
if (this.get('model.identification')) {
return this.get('forgotten').send('doForgotten', {email: this.get('model.identification')}, false);
}
this.transitionToRoute('forgotten');
}
}
});

View File

@ -140,6 +140,18 @@
color: $midgrey;
}
.forgotten-link {
display: inline-block;
height: auto;
width: auto;
margin: 0;
padding: 0;
font-size: 1.25rem;
color: darken($midgrey, 10%);
text-transform: none;
letter-spacing: 0;
}
a {
color: darken($midgrey, 10%);
font-size: 0.9em;

View File

@ -12,7 +12,7 @@
</div>
<button class="btn btn-blue" type="submit" {{action "validateAndAuthenticate"}} {{bind-attr disabled=submitting}}>Log in</button>
<section class="meta">
{{#link-to 'forgotten' class="forgotten-password"}}Forgotten password?{{/link-to}}
<button {{action 'forgotten'}} class="forgotten-link btn btn-link">Forgotten password?</button>
</section>
</form>
</section>

View File

@ -3,19 +3,20 @@
/*globals CasperTest, casper, url, user, falseUser */
CasperTest.begin('Ghost admin will load login page', 3, function suite(test) {
CasperTest.begin('Ghost admin will load login page', 4, function suite(test) {
CasperTest.Routines.signout.run(test);
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
test.assertTitle('Sign In - Test Blog', 'Ghost admin has incorrect title');
test.assertUrlMatch(/ghost\/signin\/$/, 'We should be presented with the signin page.');
casper.then(function testLink() {
var link = this.evaluate(function (selector) {
return document.querySelector(selector).getAttribute('href');
}, '.forgotten-password');
var text = this.evaluate(function (selector) {
return document.querySelector(selector).innerHTML;
}, '.forgotten-link');
casper.echoConcise('LINK' + link);
test.assert(link === '/ghost/forgotten/', 'Has correct forgotten password link');
casper.echoConcise('Text' + text);
test.assertExists('.forgotten-link');
test.assertEqual(text, 'Forgotten password?');
});
});
}, true);