auth-component
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "auth-component", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "An Authenication Component for DoneJS", | ||
@@ -5,0 +5,0 @@ "main": "src/auth-component.js", |
@@ -81,5 +81,9 @@ import $ from 'jquery'; | ||
login(username, password){ | ||
login(username, password, ev){ | ||
var self = this; | ||
if (ev) { | ||
ev.preventDefault(); | ||
} | ||
this.attr('loggingIn', true); | ||
@@ -97,2 +101,3 @@ this.attr('loginError', false); | ||
// Couldn't login with username / password. | ||
}, function(error){ | ||
@@ -118,5 +123,9 @@ self.attr('loggingIn', false); | ||
this.sendLogin(params).then(function(response){ | ||
// Check for responseTokenPath and responseDataPath. | ||
// console.log('tokenLogin response: ', response); | ||
// TODO: Check for responseTokenPath and responseDataPath. | ||
self.attr('auth', response); | ||
// Couldn't login with broken or expired token. Discard the token. | ||
}, function(){ | ||
self.attr('loading', false); | ||
self.removeStoredToken(self.attr('rememberMe'), self.attr('keyLocation')); | ||
}); | ||
@@ -149,2 +158,16 @@ }, | ||
/** | ||
* Removes the auth token from either sessionStorage or localStorage. | ||
* @param {Bookean} rememberMe If true, the token is in localStorage, | ||
* otherwise, it's in sessionStorage | ||
* @param {String} location The key name of the location in storage. | ||
*/ | ||
removeStoredToken(rememberMe, location){ | ||
if (rememberMe) { | ||
window.localStorage.removeItem(location); | ||
} else if(window.sessionStorage) { | ||
window.sessionStorage.removeItem(location); | ||
} | ||
}, | ||
/** | ||
* Toggles a loading indicator until it's decided if the login form should show or not. | ||
@@ -151,0 +174,0 @@ * @type {Boolean} |
Sorry, the diff of this file is not supported yet
153394
227