Simplify Identity
This commit is contained in:
parent
7676509fcd
commit
211ebb0e43
3 changed files with 37 additions and 18 deletions
|
@ -13,13 +13,18 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s
|
||||||
if(!Identity.isAlreadyLogin()){
|
if(!Identity.isAlreadyLogin()){
|
||||||
$('#loginModal').modal({backdrop: 'static', keyboard: false});
|
$('#loginModal').modal({backdrop: 'static', keyboard: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Manager logout event
|
||||||
$scope.$on('logoutEvent', function(){
|
$scope.$on('logoutEvent', function(){
|
||||||
$('#loginModal').modal({backdrop: 'static', keyboard: false});
|
$('#loginModal').modal({backdrop: 'static', keyboard: false});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Hide loading button and message alert
|
||||||
$('#loadingLoginButton').hide();
|
$('#loadingLoginButton').hide();
|
||||||
$('#failedToLoginAlert').hide();
|
$('#failedToLoginAlert').hide();
|
||||||
|
|
||||||
|
|
||||||
|
// Defined function for login
|
||||||
$scope.loginAction=function(){
|
$scope.loginAction=function(){
|
||||||
|
|
||||||
// Begin login state for template
|
// Begin login state for template
|
||||||
|
|
|
@ -10,7 +10,7 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($
|
||||||
{
|
{
|
||||||
|
|
||||||
// Give profile to model
|
// Give profile to model
|
||||||
$scope.profile=Identity.profile;
|
$scope.profile=Identity.getProfile();
|
||||||
|
|
||||||
// Function to logout
|
// Function to logout
|
||||||
$scope.logout=function(){
|
$scope.logout=function(){
|
||||||
|
|
|
@ -7,10 +7,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
var profile={};
|
var profile={};
|
||||||
profile.username=null;
|
profile.username=null;
|
||||||
profile.projectname=null;
|
profile.projectname=null;
|
||||||
var token={};
|
var token=null;
|
||||||
token.part_0=null;
|
|
||||||
token.part_1=null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save profile in cookies
|
* Save profile in cookies
|
||||||
*/
|
*/
|
||||||
|
@ -27,7 +26,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
var isAlreadyLogin=function(){
|
var isAlreadyLogin=function(){
|
||||||
var profileInCookie=$cookies.getObject('profile');
|
var profileInCookie=$cookies.getObject('profile');
|
||||||
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
|
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
|
||||||
var tokenPart_1InCookie=$cookies.getObject('token.part_0');
|
var tokenPart_1InCookie=$cookies.getObject('token.part_1');
|
||||||
|
|
||||||
|
|
||||||
if(typeof profileInCookie !== 'undefined'
|
if(typeof profileInCookie !== 'undefined'
|
||||||
|
@ -35,14 +34,29 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
&& typeof tokenPart_1InCookie !== 'undefined'
|
&& typeof tokenPart_1InCookie !== 'undefined'
|
||||||
){
|
){
|
||||||
angular.extend(profile, profileInCookie);
|
angular.extend(profile, profileInCookie);
|
||||||
token.part_0=tokenPart_0InCookie;
|
token=tokenPart_0InCookie+tokenPart_1InCookie;
|
||||||
token.part_1=tokenPart_1InCookie;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the profile
|
||||||
|
*/
|
||||||
|
var getProfile=function(){
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the token
|
||||||
|
*/
|
||||||
|
var getToken=function(){
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Destroy profile cookies
|
* Destroy profile cookies
|
||||||
*/
|
*/
|
||||||
|
@ -67,13 +81,18 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
requestParserResult.failReason=null;
|
requestParserResult.failReason=null;
|
||||||
|
|
||||||
if (typeof response.data.token !== 'undefined') {
|
if (typeof response.data.token !== 'undefined') {
|
||||||
|
// Set status code
|
||||||
requestParserResult.status=0;
|
requestParserResult.status=0;
|
||||||
|
|
||||||
|
// Find the middle of the token to split it
|
||||||
var middle=parseInt(response.data.token.length/2);
|
var middle=parseInt(response.data.token.length/2);
|
||||||
token.part_0=response.data.token.substring(0, middle);
|
|
||||||
token.part_1=response.data.token.substring(middle, response.data.token.length);
|
// Save profile
|
||||||
|
$cookies.putObject('profile', profile);
|
||||||
saveCookieForSession();
|
// Save first part of token
|
||||||
|
$cookies.putObject('token.part_0', response.data.token.substring(0, middle));
|
||||||
|
// Save second part of token
|
||||||
|
$cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length));
|
||||||
}
|
}
|
||||||
else if(failedToSendRequest){
|
else if(failedToSendRequest){
|
||||||
requestParserResult.failReason="Failed to send request";
|
requestParserResult.failReason="Failed to send request";
|
||||||
|
@ -84,11 +103,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
|
|
||||||
return requestParserResult;
|
return requestParserResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var getToken=function(){
|
|
||||||
return token.part_0+token.part_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to connect to OpenStack
|
* Function to connect to OpenStack
|
||||||
|
@ -121,7 +135,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
// Return services objects
|
// Return services objects
|
||||||
return {
|
return {
|
||||||
login: login,
|
login: login,
|
||||||
profile: profile,
|
getProfile: getProfile,
|
||||||
isAlreadyLogin: isAlreadyLogin,
|
isAlreadyLogin: isAlreadyLogin,
|
||||||
logout:logout,
|
logout:logout,
|
||||||
getToken:getToken
|
getToken:getToken
|
||||||
|
|
Loading…
Add table
Reference in a new issue