Handle password reset from signin page

This commit is contained in:
Jason Williams 2015-05-21 22:47:51 -05:00 committed by Hannah Wolfe
parent 50b5c9c03b
commit ce6420818a
8 changed files with 27 additions and 84 deletions

View File

@ -1,7 +1,7 @@
import Ember from 'ember';
var ApplicationController = Ember.Controller.extend({
// jscs: disable
signedOut: Ember.computed.match('currentPath', /(signin|signup|setup|forgotten|reset)/),
signedOut: Ember.computed.match('currentPath', /(signin|signup|setup|reset)/),
// jscs: enable
topNotificationCount: 0,

View File

@ -1,47 +0,0 @@
import Ember from 'ember';
import ajax from 'ghost/utils/ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';
var ForgottenController = Ember.Controller.extend(ValidationEngine, {
email: '',
submitting: false,
// ValidationEngine settings
validationType: 'forgotten',
actions: {
submit: function () {
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({
url: self.get('ghostPaths.url').api('authentication', 'passwordreset'),
type: 'POST',
data: {
passwordreset: [{
email: data.email
}]
}
}).then(function () {
self.toggleProperty('submitting');
self.notifications.showSuccess('Please check your email for instructions.', {delayed: delay});
self.set('email', '');
self.transitionToRoute('signin');
}).catch(function (resp) {
self.toggleProperty('submitting');
self.notifications.showAPIError(resp, {defaultErrorText: 'There was a problem with the reset, please try again.'});
});
}).catch(function (errors) {
self.toggleProperty('submitting');
self.notifications.showErrors(errors);
});
}
}
});
export default ForgottenController;

View File

@ -1,12 +1,14 @@
import Ember from 'ember';
import ValidationEngine from 'ghost/mixins/validation-engine';
import ajax from 'ghost/utils/ajax';
var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin, ValidationEngine, {
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
forgotten: Ember.inject.controller(),
validationType: 'signin',
submitting: false,
actions: {
authenticate: function () {
var model = this.get('model'),
@ -35,11 +37,30 @@ var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControll
},
forgotten: function () {
if (this.get('model.identification')) {
return this.get('forgotten').send('doForgotten', {email: this.get('model.identification')}, false);
var email = this.get('model.identification'),
self = this;
if (!email) {
return this.notifications.showError('Enter email address to reset password.');
}
this.transitionToRoute('forgotten');
self.set('submitting', true);
ajax({
url: self.get('ghostPaths.url').api('authentication', 'passwordreset'),
type: 'POST',
data: {
passwordreset: [{
email: email
}]
}
}).then(function () {
self.set('submitting', false);
self.notifications.showSuccess('Please check your email for instructions.');
}).catch(function (resp) {
self.set('submitting', false);
self.notifications.showAPIError(resp, {defaultErrorText: 'There was a problem with the reset, please try again.'});
});
}
}
});

View File

@ -7,7 +7,6 @@ import PostValidator from 'ghost/validators/post';
import SetupValidator from 'ghost/validators/setup';
import SignupValidator from 'ghost/validators/signup';
import SigninValidator from 'ghost/validators/signin';
import ForgotValidator from 'ghost/validators/forgotten';
import SettingValidator from 'ghost/validators/setting';
import ResetValidator from 'ghost/validators/reset';
import UserValidator from 'ghost/validators/user';
@ -74,7 +73,6 @@ var ValidationEngine = Ember.Mixin.create({
setup: SetupValidator,
signup: SignupValidator,
signin: SigninValidator,
forgotten: ForgotValidator,
setting: SettingValidator,
reset: ResetValidator,
user: UserValidator,

View File

@ -19,7 +19,6 @@ Router.map(function () {
this.route('signin');
this.route('signout');
this.route('signup', {path: '/signup/:token'});
this.route('forgotten');
this.route('reset', {path: '/reset/:token'});
this.resource('posts', {path: '/'}, function () {

View File

@ -1,11 +0,0 @@
import Ember from 'ember';
import styleBody from 'ghost/mixins/style-body';
import loadingIndicator from 'ghost/mixins/loading-indicator';
var ForgottenRoute = Ember.Route.extend(styleBody, loadingIndicator, {
titleToken: 'Forgotten Password',
classNames: ['ghost-forgotten']
});
export default ForgottenRoute;

View File

@ -10,7 +10,7 @@
<div class="form-group">
<span class="input-icon icon-lock forgotten-wrap">
{{input class="gh-input password" type="password" placeholder="Password" name="password" tabindex="2" value=model.password}}
<button type="button" {{action "forgotten"}} class="forgotten-link btn btn-link" tabindex="4">Forgot?</button>
<button type="button" {{action "forgotten"}} class="forgotten-link btn btn-link" tabindex="4" disabled={{submitting}}>Forgot?</button>
</span>
</div>
<button id="login-button" class="login btn btn-blue btn-block" type="submit" tabindex="3" disabled={{submitting}}>Sign in</button>

View File

@ -1,17 +0,0 @@
import Ember from 'ember';
var ForgotValidator = Ember.Object.create({
check: function (model) {
var data = model.getProperties('email'),
validationErrors = [];
if (!validator.isEmail(data.email)) {
validationErrors.push({
message: 'Invalid email address'
});
}
return validationErrors;
}
});
export default ForgotValidator;