From 755414cd7a772fd6e80404251a56f55984cf9da0 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 15 Jul 2015 19:52:05 -0800 Subject: [PATCH 1/3] Refactor ajax request --- app/pods/users/new/verify/route.js | 16 +++------------- app/utils/ajax-request.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 app/utils/ajax-request.js diff --git a/app/pods/users/new/verify/route.js b/app/pods/users/new/verify/route.js index 3878445..0593ba8 100644 --- a/app/pods/users/new/verify/route.js +++ b/app/pods/users/new/verify/route.js @@ -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); }, diff --git a/app/utils/ajax-request.js b/app/utils/ajax-request.js new file mode 100644 index 0000000..6225ee4 --- /dev/null +++ b/app/utils/ajax-request.js @@ -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); + }); +} From c7dc14d4f99943cfed1dd79d833784c2eedb3762 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 16 Jul 2015 12:56:19 -0800 Subject: [PATCH 2/3] catch split exception in parsebase64 --- app/utils/parse-base64.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/utils/parse-base64.js b/app/utils/parse-base64.js index deb8f8c..5735e8f 100644 --- a/app/utils/parse-base64.js +++ b/app/utils/parse-base64.js @@ -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; From c51a1deeab4b693b0a15311d8de13a981898b082 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 16 Jul 2015 18:47:12 -0800 Subject: [PATCH 3/3] Handle user lockouts (new authenticator added) --- app/authenticators/jwt-resolved.js | 18 ++++++++++++++++++ .../components/x-application/template.hbs | 2 ++ app/pods/login/template.hbs | 4 ++++ .../users/lockoutauthenticate/controller.js | 6 ++++++ app/pods/users/lockoutauthenticate/route.js | 9 +++++++++ .../users/requestlockouthelp/controller.js | 19 +++++++++++++++++++ app/pods/users/requestlockouthelp/route.js | 8 ++++++++ .../users/requestlockouthelp/template.hbs | 18 ++++++++++++++++++ app/router.js | 2 ++ 9 files changed, 86 insertions(+) create mode 100644 app/authenticators/jwt-resolved.js create mode 100644 app/pods/users/lockoutauthenticate/controller.js create mode 100644 app/pods/users/lockoutauthenticate/route.js create mode 100644 app/pods/users/requestlockouthelp/controller.js create mode 100644 app/pods/users/requestlockouthelp/route.js create mode 100644 app/pods/users/requestlockouthelp/template.hbs diff --git a/app/authenticators/jwt-resolved.js b/app/authenticators/jwt-resolved.js new file mode 100644 index 0000000..a6884ec --- /dev/null +++ b/app/authenticators/jwt-resolved.js @@ -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)); + }); + }, + +}); diff --git a/app/pods/components/x-application/template.hbs b/app/pods/components/x-application/template.hbs index 04d7ca2..635b605 100644 --- a/app/pods/components/x-application/template.hbs +++ b/app/pods/components/x-application/template.hbs @@ -30,6 +30,8 @@ {{link-to 'Login' 'login'}}
{{link-to 'Sign Up' 'users.new'}} +
+ {{link-to 'Locked Out?' 'users.requestlockouthelp'}}

{{/if}} diff --git a/app/pods/login/template.hbs b/app/pods/login/template.hbs index 8f07896..7d3f5ac 100644 --- a/app/pods/login/template.hbs +++ b/app/pods/login/template.hbs @@ -8,5 +8,9 @@ {{input value=password type="password" placeholder="Password"}} {{input class="button-gray" type="submit" value="Log In"}} +
+
+ Forget your password? {{link-to 'Request a lockout email.' 'users.requestlockouthelp'}} +
{{/if}} {{/x-application}} diff --git a/app/pods/users/lockoutauthenticate/controller.js b/app/pods/users/lockoutauthenticate/controller.js new file mode 100644 index 0000000..79734b5 --- /dev/null +++ b/app/pods/users/lockoutauthenticate/controller.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + queryParams: ['token'], + +}); diff --git a/app/pods/users/lockoutauthenticate/route.js b/app/pods/users/lockoutauthenticate/route.js new file mode 100644 index 0000000..131628c --- /dev/null +++ b/app/pods/users/lockoutauthenticate/route.js @@ -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); + }, + +}); diff --git a/app/pods/users/requestlockouthelp/controller.js b/app/pods/users/requestlockouthelp/controller.js new file mode 100644 index 0000000..205f73c --- /dev/null +++ b/app/pods/users/requestlockouthelp/controller.js @@ -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'); + }, + + }, + +}); diff --git a/app/pods/users/requestlockouthelp/route.js b/app/pods/users/requestlockouthelp/route.js new file mode 100644 index 0000000..19831b4 --- /dev/null +++ b/app/pods/users/requestlockouthelp/route.js @@ -0,0 +1,8 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + deactivate: function() { + this.controller.set('email', null); + }, + +}); diff --git a/app/pods/users/requestlockouthelp/template.hbs b/app/pods/users/requestlockouthelp/template.hbs new file mode 100644 index 0000000..f348427 --- /dev/null +++ b/app/pods/users/requestlockouthelp/template.hbs @@ -0,0 +1,18 @@ +
+
+
+ Account Lockout Access +
+
    +
  • + + {{input value=email}} +
  • +
  • + +
  • +
+
+
+
+
diff --git a/app/router.js b/app/router.js index 3dc92aa..c34e885 100644 --- a/app/router.js +++ b/app/router.js @@ -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' }); });