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:
Matthew Dillon 2015-07-16 21:13:54 -08:00
commit c996dd5374
12 changed files with 104 additions and 14 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'}} {{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>

View file

@ -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}}

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

@ -1,4 +1,5 @@
import Ember from 'ember'; import Ember from 'ember';
import ajaxRequest from '../../../../utils/ajax-request';
export default Ember.Route.extend({ export default Ember.Route.extend({
apiURL: function() { apiURL: function() {
@ -10,19 +11,8 @@ export default Ember.Route.extend({
}.property(), }.property(),
model: function(params) { model: function(params) {
let url = this.get('apiURL') + '/api/' + this.get('genus') + '/users/verify/' + params.nonce; let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`;
return new Ember.RSVP.Promise(function(resolve, reject) { return ajaxRequest(url);
let options = {
success: function(data){
resolve(data);
},
error: function(jqXHR, status, error){
reject(jqXHR, status, error);
},
dataType: 'text json',
};
Ember.$.ajax(url, options);
});
}, },

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

13
app/utils/ajax-request.js Normal file
View 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);
});
}

View file

@ -1,6 +1,7 @@
export default function parseBase64(token) { export default function parseBase64(token) {
let tokenData = atob(token.split('.')[1]); let tokenData;
try { try {
tokenData = atob(token.split('.')[1]);
return JSON.parse(tokenData); return JSON.parse(tokenData);
} catch (e) { } catch (e) {
return tokenData; return tokenData;