Merge branch 'master' into clostridium
* master: Handle user lockouts (new authenticator added) catch split exception in parsebase64 Refactor ajax request
This commit is contained in:
commit
c996dd5374
12 changed files with 104 additions and 14 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'}}
|
||||
<br>
|
||||
{{link-to 'Sign Up' 'users.new'}}
|
||||
<br>
|
||||
{{link-to 'Locked Out?' 'users.requestlockouthelp'}}
|
||||
</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
|
@ -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}}
|
||||
|
|
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);
|
||||
},
|
||||
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import Ember from 'ember';
|
||||
import ajaxRequest from '../../../../utils/ajax-request';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
apiURL: function() {
|
||||
|
@ -10,19 +11,8 @@ export default Ember.Route.extend({
|
|||
}.property(),
|
||||
|
||||
model: function(params) {
|
||||
let url = this.get('apiURL') + '/api/' + this.get('genus') + '/users/verify/' + params.nonce;
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
let options = {
|
||||
success: function(data){
|
||||
resolve(data);
|
||||
},
|
||||
error: function(jqXHR, status, error){
|
||||
reject(jqXHR, status, error);
|
||||
},
|
||||
dataType: 'text json',
|
||||
};
|
||||
Ember.$.ajax(url, options);
|
||||
});
|
||||
let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`;
|
||||
return ajaxRequest(url);
|
||||
},
|
||||
|
||||
|
||||
|
|
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('users', function() {
|
||||
this.route('requestlockouthelp');
|
||||
this.route('lockoutauthenticate');
|
||||
this.route('new', function() {
|
||||
this.route('verify', { path: 'verify/:nonce' });
|
||||
});
|
||||
|
|
13
app/utils/ajax-request.js
Normal file
13
app/utils/ajax-request.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
export default function ajaxRequest(url, options) {
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
options = options || {};
|
||||
options.url = url;
|
||||
options.success = function(data) {
|
||||
resolve(data);
|
||||
};
|
||||
options.error = function(jqXHR, status, error) {
|
||||
reject(jqXHR, status, error);
|
||||
};
|
||||
Ember.$.ajax(options);
|
||||
});
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
export default function parseBase64(token) {
|
||||
let tokenData = atob(token.split('.')[1]);
|
||||
let tokenData;
|
||||
try {
|
||||
tokenData = atob(token.split('.')[1]);
|
||||
return JSON.parse(tokenData);
|
||||
} catch (e) {
|
||||
return tokenData;
|
||||
|
|
Reference in a new issue