Handle user lockouts (new authenticator added)
This commit is contained in:
parent
c7dc14d4f9
commit
c51a1deeab
9 changed files with 86 additions and 0 deletions
18
app/authenticators/jwt-resolved.js
Normal file
18
app/authenticators/jwt-resolved.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import JwtTokenAuthenticator from 'simple-auth-token/authenticators/jwt';
|
||||||
|
|
||||||
|
export default JwtTokenAuthenticator.extend({
|
||||||
|
authenticate: function(token) {
|
||||||
|
return new Ember.RSVP.Promise(resolve => {
|
||||||
|
let tokenData = this.getTokenData(token);
|
||||||
|
let expiresAt = tokenData[this.tokenExpireName];
|
||||||
|
let response = {};
|
||||||
|
response[this.tokenPropertyName] = token;
|
||||||
|
response.expiresAt = expiresAt;
|
||||||
|
this.scheduleAccessTokenRefresh(expiresAt, token);
|
||||||
|
|
||||||
|
resolve(this.getResponseData(response));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
|
@ -30,6 +30,8 @@
|
||||||
{{link-to 'Login' 'login'}}
|
{{link-to 'Login' 'login'}}
|
||||||
<br>
|
<br>
|
||||||
{{link-to 'Sign Up' 'users.new'}}
|
{{link-to 'Sign Up' 'users.new'}}
|
||||||
|
<br>
|
||||||
|
{{link-to 'Locked Out?' 'users.requestlockouthelp'}}
|
||||||
</p>
|
</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,5 +8,9 @@
|
||||||
{{input value=password type="password" placeholder="Password"}}
|
{{input value=password type="password" placeholder="Password"}}
|
||||||
{{input class="button-gray" type="submit" value="Log In"}}
|
{{input class="button-gray" type="submit" value="Log In"}}
|
||||||
</form>
|
</form>
|
||||||
|
<br>
|
||||||
|
<div>
|
||||||
|
Forget your password? {{link-to 'Request a lockout email.' 'users.requestlockouthelp'}}
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/x-application}}
|
{{/x-application}}
|
||||||
|
|
6
app/pods/users/lockoutauthenticate/controller.js
Normal file
6
app/pods/users/lockoutauthenticate/controller.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Controller.extend({
|
||||||
|
queryParams: ['token'],
|
||||||
|
|
||||||
|
});
|
9
app/pods/users/lockoutauthenticate/route.js
Normal file
9
app/pods/users/lockoutauthenticate/route.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Route.extend({
|
||||||
|
beforeModel: function(transition) {
|
||||||
|
let token = Ember.get(transition, 'queryParams.token');
|
||||||
|
this.get('session').authenticate('authenticator:jwt-resolved', token);
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
19
app/pods/users/requestlockouthelp/controller.js
Normal file
19
app/pods/users/requestlockouthelp/controller.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import ajaxRequest from '../../../utils/ajax-request';
|
||||||
|
|
||||||
|
export default Ember.Controller.extend({
|
||||||
|
actions: {
|
||||||
|
save: function() {
|
||||||
|
let url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/lockout`;
|
||||||
|
let options = {
|
||||||
|
method: 'POST',
|
||||||
|
data: { email: this.get('email') },
|
||||||
|
};
|
||||||
|
ajaxRequest(url, options);
|
||||||
|
this.transitionTo('login');
|
||||||
|
this.get('flashMessages').information('Please check your email');
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
8
app/pods/users/requestlockouthelp/route.js
Normal file
8
app/pods/users/requestlockouthelp/route.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Route.extend({
|
||||||
|
deactivate: function() {
|
||||||
|
this.controller.set('email', null);
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
18
app/pods/users/requestlockouthelp/template.hbs
Normal file
18
app/pods/users/requestlockouthelp/template.hbs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<div class="grid-1">
|
||||||
|
<div class="span-1">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Account Lockout Access</legend>
|
||||||
|
<form {{action 'save' on='submit'}}>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<label>Email</label>
|
||||||
|
{{input value=email}}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button type="submit" class="button-green smaller">Submit</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</form>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -9,6 +9,8 @@ Router.map(function() {
|
||||||
this.route('login');
|
this.route('login');
|
||||||
|
|
||||||
this.route('users', function() {
|
this.route('users', function() {
|
||||||
|
this.route('requestlockouthelp');
|
||||||
|
this.route('lockoutauthenticate');
|
||||||
this.route('new', function() {
|
this.route('new', function() {
|
||||||
this.route('verify', { path: 'verify/:nonce' });
|
this.route('verify', { path: 'verify/:nonce' });
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue