mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Handle password reset from signin page
This commit is contained in:
parent
ca21e055be
commit
4369727cd6
8 changed files with 27 additions and 84 deletions
|
@ -1,7 +1,7 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
var ApplicationController = Ember.Controller.extend({
|
var ApplicationController = Ember.Controller.extend({
|
||||||
// jscs: disable
|
// jscs: disable
|
||||||
signedOut: Ember.computed.match('currentPath', /(signin|signup|setup|forgotten|reset)/),
|
signedOut: Ember.computed.match('currentPath', /(signin|signup|setup|reset)/),
|
||||||
// jscs: enable
|
// jscs: enable
|
||||||
|
|
||||||
topNotificationCount: 0,
|
topNotificationCount: 0,
|
||||||
|
|
|
@ -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;
|
|
|
@ -1,12 +1,14 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import ValidationEngine from 'ghost/mixins/validation-engine';
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
||||||
|
import ajax from 'ghost/utils/ajax';
|
||||||
|
|
||||||
var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin, ValidationEngine, {
|
var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin, ValidationEngine, {
|
||||||
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
|
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
|
||||||
forgotten: Ember.inject.controller(),
|
|
||||||
|
|
||||||
validationType: 'signin',
|
validationType: 'signin',
|
||||||
|
|
||||||
|
submitting: false,
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
authenticate: function () {
|
authenticate: function () {
|
||||||
var model = this.get('model'),
|
var model = this.get('model'),
|
||||||
|
@ -35,11 +37,30 @@ var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControll
|
||||||
},
|
},
|
||||||
|
|
||||||
forgotten: function () {
|
forgotten: function () {
|
||||||
if (this.get('model.identification')) {
|
var email = this.get('model.identification'),
|
||||||
return this.get('forgotten').send('doForgotten', {email: this.get('model.identification')}, false);
|
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.'});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,6 @@ import PostValidator from 'ghost/validators/post';
|
||||||
import SetupValidator from 'ghost/validators/setup';
|
import SetupValidator from 'ghost/validators/setup';
|
||||||
import SignupValidator from 'ghost/validators/signup';
|
import SignupValidator from 'ghost/validators/signup';
|
||||||
import SigninValidator from 'ghost/validators/signin';
|
import SigninValidator from 'ghost/validators/signin';
|
||||||
import ForgotValidator from 'ghost/validators/forgotten';
|
|
||||||
import SettingValidator from 'ghost/validators/setting';
|
import SettingValidator from 'ghost/validators/setting';
|
||||||
import ResetValidator from 'ghost/validators/reset';
|
import ResetValidator from 'ghost/validators/reset';
|
||||||
import UserValidator from 'ghost/validators/user';
|
import UserValidator from 'ghost/validators/user';
|
||||||
|
@ -74,7 +73,6 @@ var ValidationEngine = Ember.Mixin.create({
|
||||||
setup: SetupValidator,
|
setup: SetupValidator,
|
||||||
signup: SignupValidator,
|
signup: SignupValidator,
|
||||||
signin: SigninValidator,
|
signin: SigninValidator,
|
||||||
forgotten: ForgotValidator,
|
|
||||||
setting: SettingValidator,
|
setting: SettingValidator,
|
||||||
reset: ResetValidator,
|
reset: ResetValidator,
|
||||||
user: UserValidator,
|
user: UserValidator,
|
||||||
|
|
|
@ -19,7 +19,6 @@ Router.map(function () {
|
||||||
this.route('signin');
|
this.route('signin');
|
||||||
this.route('signout');
|
this.route('signout');
|
||||||
this.route('signup', {path: '/signup/:token'});
|
this.route('signup', {path: '/signup/:token'});
|
||||||
this.route('forgotten');
|
|
||||||
this.route('reset', {path: '/reset/:token'});
|
this.route('reset', {path: '/reset/:token'});
|
||||||
|
|
||||||
this.resource('posts', {path: '/'}, function () {
|
this.resource('posts', {path: '/'}, function () {
|
||||||
|
|
|
@ -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;
|
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<span class="input-icon icon-lock forgotten-wrap">
|
<span class="input-icon icon-lock forgotten-wrap">
|
||||||
{{input class="gh-input password" type="password" placeholder="Password" name="password" tabindex="2" value=model.password}}
|
{{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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<button id="login-button" class="login btn btn-blue btn-block" type="submit" tabindex="3" disabled={{submitting}}>Sign in</button>
|
<button id="login-button" class="login btn btn-blue btn-block" type="submit" tabindex="3" disabled={{submitting}}>Sign in</button>
|
||||||
|
|
|
@ -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;
|
|
Loading…
Add table
Reference in a new issue