mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Merge pull request #3150 from javorszky/iss2843
Made ember version of reset password work
This commit is contained in:
commit
bb72274a9d
6 changed files with 85 additions and 69 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
/* jshint unused: false */
|
||||||
|
import ajax from 'ghost/utils/ajax';
|
||||||
import ValidationEngine from 'ghost/mixins/validation-engine';
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
||||||
|
|
||||||
var ForgottenController = Ember.Controller.extend(ValidationEngine, {
|
var ForgottenController = Ember.Controller.extend(ValidationEngine, {
|
||||||
|
@ -9,20 +11,27 @@ var ForgottenController = Ember.Controller.extend(ValidationEngine, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
submit: function () {
|
submit: function () {
|
||||||
var self = this;
|
var self = this,
|
||||||
|
data = self.getProperties('email');
|
||||||
|
|
||||||
this.toggleProperty('submitting');
|
this.toggleProperty('submitting');
|
||||||
this.validate({ format: false }).then(function () {
|
this.validate({ format: false }).then(function () {
|
||||||
self.user.fetchForgottenPasswordFor(this.email)
|
ajax({
|
||||||
.then(function () {
|
url: self.get('ghostPaths').apiUrl('authentication', 'passwordreset'),
|
||||||
self.toggleProperty('submitting');
|
type: 'POST',
|
||||||
self.notifications.showSuccess('Please check your email for instructions.');
|
data: {
|
||||||
self.transitionToRoute('signin');
|
passwordreset: [{
|
||||||
})
|
email: data.email
|
||||||
.catch(function (resp) {
|
}]
|
||||||
self.toggleProperty('submitting');
|
}
|
||||||
self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.');
|
}).then(function (resp) {
|
||||||
});
|
self.toggleProperty('submitting');
|
||||||
|
self.notifications.showSuccess('Please check your email for instructions.');
|
||||||
|
self.transitionToRoute('signin');
|
||||||
|
}).catch(function (resp) {
|
||||||
|
self.toggleProperty('submitting');
|
||||||
|
self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.');
|
||||||
|
});
|
||||||
}).catch(function (errors) {
|
}).catch(function (errors) {
|
||||||
self.toggleProperty('submitting');
|
self.toggleProperty('submitting');
|
||||||
self.notifications.showErrors(errors);
|
self.notifications.showErrors(errors);
|
||||||
|
|
|
@ -1,28 +1,48 @@
|
||||||
/*global alert, console */
|
/*global console*/
|
||||||
var ResetController = Ember.Controller.extend({
|
/* jshint unused: false */
|
||||||
|
import ajax from 'ghost/utils/ajax';
|
||||||
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
||||||
|
|
||||||
|
var ResetController = Ember.Controller.extend(ValidationEngine, {
|
||||||
passwords: {
|
passwords: {
|
||||||
newPassword: '',
|
newPassword: '',
|
||||||
ne2Password: ''
|
ne2Password: ''
|
||||||
},
|
},
|
||||||
token: '',
|
token: '',
|
||||||
submitButtonDisabled: false,
|
submitButtonDisabled: false,
|
||||||
|
|
||||||
|
validationType: 'reset',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
submit: function () {
|
submit: function () {
|
||||||
var self = this;
|
var self = this,
|
||||||
this.set('submitButtonDisabled', true);
|
data = self.getProperties('passwords', 'token');
|
||||||
|
|
||||||
this.user.resetPassword(this.passwords, this.token)
|
this.toggleProperty('submitting');
|
||||||
.then(function () {
|
this.validate({format: false}).then(function () {
|
||||||
alert('@TODO Notification : Success');
|
ajax({
|
||||||
|
url: self.get('ghostPaths').apiUrl('authentication', 'passwordreset'),
|
||||||
|
type: 'PUT',
|
||||||
|
data: {
|
||||||
|
passwordreset: [{
|
||||||
|
newPassword: data.passwords.newPassword,
|
||||||
|
ne2Password: data.passwords.ne2Password,
|
||||||
|
token: data.token
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}).then(function (resp) {
|
||||||
|
self.toggleProperty('submitting');
|
||||||
|
console.log('success');
|
||||||
self.transitionToRoute('signin');
|
self.transitionToRoute('signin');
|
||||||
})
|
}).catch(function (errors) {
|
||||||
.catch(function (response) {
|
self.toggleProperty('submitting');
|
||||||
alert('@TODO Notification : Failure');
|
console.log('error');
|
||||||
console.log(response);
|
|
||||||
})
|
|
||||||
.finally(function () {
|
|
||||||
self.set('submitButtonDisabled', false);
|
|
||||||
});
|
});
|
||||||
|
}).catch(function (error) {
|
||||||
|
self.toggleProperty('submitting');
|
||||||
|
// @TODO: notifications here for validation errors
|
||||||
|
console.log('validation error', error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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 ForgotValidator from 'ghost/validators/forgotten';
|
||||||
import SettingValidator from 'ghost/validators/setting';
|
import SettingValidator from 'ghost/validators/setting';
|
||||||
|
import ResetValidator from 'ghost/validators/reset';
|
||||||
|
|
||||||
ValidatorExtensions.init();
|
ValidatorExtensions.init();
|
||||||
|
|
||||||
|
@ -17,7 +18,8 @@ var ValidationEngine = Ember.Mixin.create({
|
||||||
signup: SignupValidator,
|
signup: SignupValidator,
|
||||||
signin: SigninValidator,
|
signin: SigninValidator,
|
||||||
forgotten: ForgotValidator,
|
forgotten: ForgotValidator,
|
||||||
setting: SettingValidator
|
setting: SettingValidator,
|
||||||
|
reset: ResetValidator
|
||||||
},
|
},
|
||||||
|
|
||||||
validate: function (opts) {
|
validate: function (opts) {
|
||||||
|
|
|
@ -71,50 +71,9 @@ var User = DS.Model.extend({
|
||||||
return validationErrors;
|
return validationErrors;
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchForgottenPasswordFor: function (email) {
|
|
||||||
var forgottenUrl = this.get('ghostPaths').apiUrl('forgotten');
|
|
||||||
|
|
||||||
return new Ember.RSVP.Promise(function (resolve, reject) {
|
|
||||||
if (!validator.isEmail(email)) {
|
|
||||||
reject(new Error('Please enter a correct email address.'));
|
|
||||||
} else {
|
|
||||||
resolve(ic.ajax.request(forgottenUrl, {
|
|
||||||
type: 'POST',
|
|
||||||
headers: {
|
|
||||||
// @TODO Find a more proper way to do this.
|
|
||||||
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
email: email
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
resetPassword: function (passwords, token) {
|
|
||||||
var self = this,
|
|
||||||
resetUrl = this.get('ghostPaths').apiUrl('reset');
|
|
||||||
|
|
||||||
return new Ember.RSVP.Promise(function (resolve, reject) {
|
|
||||||
if (!self.validatePassword(passwords).get('passwordIsValid')) {
|
|
||||||
reject(new Error('Errors found! ' + JSON.stringify(self.get('passwordErrors'))));
|
|
||||||
} else {
|
|
||||||
resolve(ic.ajax.request(resetUrl, {
|
|
||||||
type: 'POST',
|
|
||||||
headers: {
|
|
||||||
// @TODO: find a more proper way to do this.
|
|
||||||
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
newpassword: passwords.newPassword,
|
|
||||||
ne2password: passwords.ne2Password,
|
|
||||||
token: token
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default User;
|
export default User;
|
||||||
|
|
|
@ -4,7 +4,9 @@ var ForgotValidator = Ember.Object.create({
|
||||||
validationErrors = [];
|
validationErrors = [];
|
||||||
|
|
||||||
if (!validator.isEmail(data.email)) {
|
if (!validator.isEmail(data.email)) {
|
||||||
validationErrors.push('Invalid Email');
|
validationErrors.push({
|
||||||
|
message: 'Invalid Email'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return validationErrors;
|
return validationErrors;
|
||||||
|
|
24
ghost/admin/validators/reset.js
Normal file
24
ghost/admin/validators/reset.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
var ResetValidator = Ember.Object.create({
|
||||||
|
validate: function (model) {
|
||||||
|
|
||||||
|
var data = model.getProperties('passwords'),
|
||||||
|
p1 = data.passwords.newPassword,
|
||||||
|
p2 = data.passwords.ne2Password,
|
||||||
|
validationErrors = [];
|
||||||
|
|
||||||
|
if (!validator.equals(p1, p2)) {
|
||||||
|
validationErrors.push({
|
||||||
|
message: 'The two new passwords don\'t match.'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validator.isLength(p1, 8)) {
|
||||||
|
validationErrors.push({
|
||||||
|
message: 'The password is not long enough.'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return validationErrors;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ResetValidator;
|
Loading…
Add table
Reference in a new issue