Handle user lockouts (new authenticator added)

This commit is contained in:
Matthew Dillon 2015-07-16 18:47:12 -08:00
parent c7dc14d4f9
commit c51a1deeab
9 changed files with 86 additions and 0 deletions

View 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));
});
},
});

View file

@ -30,6 +30,8 @@
{{link-to 'Login' 'login'}}
<br>
{{link-to 'Sign Up' 'users.new'}}
<br>
{{link-to 'Locked Out?' 'users.requestlockouthelp'}}
</p>
{{/if}}
</div>

View file

@ -8,5 +8,9 @@
{{input value=password type="password" placeholder="Password"}}
{{input class="button-gray" type="submit" value="Log In"}}
</form>
<br>
<div>
Forget your password? {{link-to 'Request a lockout email.' 'users.requestlockouthelp'}}
</div>
{{/if}}
{{/x-application}}

View file

@ -0,0 +1,6 @@
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['token'],
});

View 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);
},
});

View 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');
},
},
});

View file

@ -0,0 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
deactivate: function() {
this.controller.set('email', null);
},
});

View 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>

View file

@ -9,6 +9,8 @@ Router.map(function() {
this.route('login');
this.route('users', function() {
this.route('requestlockouthelp');
this.route('lockoutauthenticate');
this.route('new', function() {
this.route('verify', { path: 'verify/:nonce' });
});