-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reset and forgot password functionality
- Loading branch information
Showing
25 changed files
with
620 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Ember from 'ember'; | ||
const { Component, set, get, inject: { service } } = Ember; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default Component.extend({ | ||
classNames: ['form--centered', 'forgot-password-form'], | ||
|
||
/** | ||
* @property flashMessages | ||
* @type Ember.Service | ||
*/ | ||
flashMessages: service(), | ||
|
||
/** | ||
* @property email | ||
* @default String | ||
*/ | ||
email: '', | ||
/** | ||
* @property error | ||
*/ | ||
error: null, | ||
|
||
/** | ||
* @property forgotPasswordTask | ||
* @param email | ||
*/ | ||
forgotPasswordTask: task(function* (email) { | ||
try { | ||
yield get(this, 'forgotPassword')(email); | ||
get(this, 'flashMessages').clearMessages().success("Check your email for a link to reset your password. If it doesn't appear within a few minutes, check your spam folder or double-check whether you have an account with this email."); | ||
set(this, 'error', null); | ||
} catch(e) { | ||
set(this, 'error', e); | ||
} | ||
}), | ||
|
||
actions: { | ||
|
||
/** | ||
* @method forgotPassword | ||
* @param email | ||
*/ | ||
forgotPassword(email) { | ||
return get(this, 'forgotPasswordTask').perform(email); | ||
} | ||
|
||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Ember from 'ember'; | ||
const { Component, set, get, inject: { service } } = Ember; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default Component.extend({ | ||
classNames: ['form--centered', 'reset-password-form'], | ||
|
||
/** | ||
* @property flashMessages | ||
* @type Ember.Service | ||
*/ | ||
flashMessages: service(), | ||
/** | ||
* @property password | ||
* @default String | ||
*/ | ||
password: '', | ||
/** | ||
* @property passwordConfirmation | ||
* @default String | ||
*/ | ||
passwordConfirmation: '', | ||
/** | ||
* @property error | ||
*/ | ||
error: null, | ||
|
||
/** | ||
* @property resetPasswordTask | ||
* @param password | ||
* @param passwordConfirmation | ||
*/ | ||
resetPasswordTask: task(function* (password, passwordConfirmation) { | ||
try { | ||
yield get(this, 'resetPassword')(password, passwordConfirmation); | ||
get(this, 'flashMessages').clearMessages().success("Your password has been reset and you're now signed in."); | ||
set(this, 'error', null); | ||
} catch(e) { | ||
set(this, 'error', e); | ||
} | ||
}), | ||
|
||
actions: { | ||
|
||
/** | ||
* @method resetPassword | ||
* @param password | ||
* @param passwordConfirmation | ||
*/ | ||
resetPassword(password, passwordConfirmation) { | ||
return get(this, 'resetPasswordTask').perform(password, passwordConfirmation); | ||
} | ||
|
||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Ember from 'ember'; | ||
const { Route, get, inject: { service } } = Ember; | ||
|
||
export default Route.extend({ | ||
|
||
ajax: service(), | ||
|
||
actions: { | ||
forgotPassword(email) { | ||
return get(this, 'ajax').request('/password/forgot', { | ||
method: 'POST', | ||
data: { | ||
} | ||
}).then(() => { | ||
this.transitionTo('index'); | ||
}); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Ember from 'ember'; | ||
const { Route, get, set, inject: { service } } = Ember; | ||
|
||
export default Route.extend({ | ||
queryParams: { | ||
token: { refreshModel: true } | ||
}, | ||
|
||
ajax: service(), | ||
session: service(), | ||
|
||
model(params) { | ||
return params.token; | ||
}, | ||
|
||
setupController(controller, model) { | ||
set(controller, 'token', model); | ||
}, | ||
|
||
actions: { | ||
resetPassword(password, passwordConfirmation) { | ||
return get(this, 'ajax').request('/password/reset', { | ||
method: 'POST', | ||
data: { | ||
token: get(this, 'controller.token'), | ||
password, | ||
'password-confirmation': passwordConfirmation | ||
} | ||
}).then((response) => { | ||
return get(this, 'session').authenticate('authenticator:jwt', { identification: response.email, password }); | ||
}); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{{#each messages as |message|}} | ||
<p class="error">{{message}}</p> | ||
<p class="error" data-test-id="error-msg">{{message}}</p> | ||
{{else}} | ||
<p class="error">{{defaultMessage}}</p> | ||
<p class="error" data-test-id="default-msg">{{defaultMessage}}</p> | ||
{{/each}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="container"> | ||
<form> | ||
<h2>Reset your password</h2> | ||
|
||
<p data-test-id="forgot-password-header">Enter your email and we'll send you a link to reset your password.</p> | ||
|
||
<div class="input-group"> | ||
{{#auto-focus}} | ||
{{input name="email" autocapitalize="off" type="text" value=email}} | ||
{{/auto-focus}} | ||
</div> | ||
|
||
<div class="input-group"> | ||
<button id="reset-password" class="default" type="submit" disabled={{isLoading}} {{action "forgotPassword" email}}> | ||
Send password reset email | ||
</button> | ||
</div> | ||
|
||
{{#if error}} | ||
{{error-formatter error=error}} | ||
{{/if}} | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<div class="container"> | ||
<form> | ||
<h2>Change your password</h2> | ||
|
||
<div class="input-group"> | ||
<label data-test-id="password-label">Password</label> | ||
{{#auto-focus}} | ||
{{input id="password" autofocus="true" class="has-progress" name="password" type="password" autocomplete="off" value=password}} | ||
{{/auto-focus}} | ||
</div> | ||
|
||
<div class="input-group"> | ||
<label data-test-id="password-confirmation-label">Confirm password</label> | ||
{{input id="password-confirmation" class="has-progress" name="password" type="password" autocomplete="off" value=passwordConfirmation}} | ||
</div> | ||
|
||
<div class="input-group"> | ||
<button id="reset-password" class="default" type="submit" disabled={{resetPasswordTask.isRunning}} {{action "resetPassword" password passwordConfirmation}}> | ||
Change password | ||
</button> | ||
</div> | ||
|
||
{{#if error}} | ||
{{error-formatter error=error}} | ||
{{/if}} | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{password/forgot-password | ||
forgotPassword=(route-action "forgotPassword") | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{password/reset-password | ||
resetPassword=(route-action "resetPassword") | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.