From c2e8299e672dd5c98e4db3b72fb64074300e6ec4 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 13:34:06 -0700 Subject: [PATCH] Can log in now --- app/authenticators/oauth2.js | 6 ++++++ app/pods/login/controller.js | 12 ++++++------ app/pods/users/lockoutauthenticate/route.js | 2 ++ config/environment.js | 3 +++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 app/authenticators/oauth2.js diff --git a/app/authenticators/oauth2.js b/app/authenticators/oauth2.js new file mode 100644 index 0000000..c5c9221 --- /dev/null +++ b/app/authenticators/oauth2.js @@ -0,0 +1,6 @@ +import OAuth2PasswordGrant from 'ember-simple-auth/authenticators/oauth2-password-grant'; +import config from '../config/environment'; + +export default OAuth2PasswordGrant.extend({ + serverTokenEndpoint: `${config.apiURL}/api/authenticate`, +}); diff --git a/app/pods/login/controller.js b/app/pods/login/controller.js index 42e761d..13eed49 100644 --- a/app/pods/login/controller.js +++ b/app/pods/login/controller.js @@ -1,21 +1,21 @@ import Ember from 'ember'; export default Ember.Controller.extend({ + session: Ember.inject.service('session'), + loading: false, actions: { authenticate: function() { - let credentials = this.getProperties('identification', 'password'); - let session = this.get('session'); - let authenticator = 'simple-auth-authenticator:jwt'; - // Manually clean up because there might not be a transition this.get('flashMessages').clearMessages(); - this.set('loading', true).then(session.authenticate(authenticator, credentials).catch((error) => { + let { identification, password } = this.getProperties('identification', 'password'); + this.set('loading', true) + this.get('session').authenticate('authenticator:oauth2', identification, password).catch((error) => { this.transitionToRoute('login'); this.set('loading', false); this.get('flashMessages').error(error.error); - })); + }); this.set('loading', false); } } diff --git a/app/pods/users/lockoutauthenticate/route.js b/app/pods/users/lockoutauthenticate/route.js index f77c5dc..9924157 100644 --- a/app/pods/users/lockoutauthenticate/route.js +++ b/app/pods/users/lockoutauthenticate/route.js @@ -1,6 +1,8 @@ import Ember from 'ember'; export default Ember.Route.extend({ + session: Ember.inject.service('session'), + beforeModel: function(transition) { this._super(transition); diff --git a/config/environment.js b/config/environment.js index 2b1e044..824739a 100644 --- a/config/environment.js +++ b/config/environment.js @@ -20,6 +20,9 @@ module.exports = function(environment) { type: 'error', types: ['error', 'warning', 'success', 'information', 'tip', 'message'], }, + 'ember-simple-auth': { + routeAfterAuthentication: 'protected.compare', + }, }; var apiURL;