0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

Merge pull request #2510 from szelpe/ember-forgotten-2411

Created ForgottenController
This commit is contained in:
Hannah Wolfe 2014-03-31 10:37:06 +01:00
commit 397cd6c37c
4 changed files with 48 additions and 3 deletions

View file

@ -0,0 +1,21 @@
/*global console, alert */
var ForgottenController = Ember.Controller.extend({
email: '',
actions: {
submit: function () {
var self = this;
self.user.fetchForgottenPasswordFor(this.email)
.then(function () {
alert('@TODO Notification: Success');
self.transitionToRoute('signin');
})
.catch(function (response) {
alert('@TODO');
console.log(response);
});
}
}
});
export default ForgottenController;

View file

@ -39,6 +39,9 @@ var defineFixtures = function (status) {
ic.ajax.defineFixture('/ghost/changepw/', response({
msg: 'Password changed successfully'
}));
ic.ajax.defineFixture('/ghost/api/v0.1/forgotten/', response({
redirect: '/ghost/signin/'
}));
};
export default defineFixtures;

View file

@ -2,6 +2,7 @@ import BaseModel from 'ghost/models/base';
var UserModel = BaseModel.extend({
url: BaseModel.apiRoot + '/users/me/',
forgottenUrl: BaseModel.apiRoot + '/forgotten/',
save: function () {
return ic.ajax.request(this.url, {
@ -74,6 +75,26 @@ var UserModel = BaseModel.extend({
this.set('passwordErrors', validationErrors);
return this;
},
fetchForgottenPasswordFor: function (email) {
var self = this;
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(self.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
}
}));
}
});
}
});

View file

@ -1,8 +1,8 @@
<section class="forgotten-box js-forgotten-box">
<form id="forgotten" class="forgotten-form" method="post" novalidate="novalidate">
<form id="forgotten" class="forgotten-form" method="post" novalidate="novalidate" {{action "submit" on="submit"}}>
<div class="email-wrap">
<input class="email" type="email" placeholder="Email Address" name="email" autocapitalize="off" autocorrect="off">
{{input value=email class="email" type="email" placeholder="Email Address" name="email" autocapitalize="off" autocorrect="off"}}
</div>
<button class="button-save" type="submit">Send new password</button>
</form>
</section>
</section>