Add ';' and correct indent
This commit is contained in:
parent
fdfdd27a35
commit
968eda48cc
1 changed files with 146 additions and 148 deletions
|
@ -1,36 +1,36 @@
|
||||||
|
|
||||||
mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http, $cookies, $rootScope){
|
mainApp.factory('Identity', ['$http', '$cookies', '$rootScope', function ($http, $cookies, $rootScope) {
|
||||||
|
|
||||||
/* Create profile structure to store informations
|
/* Create profile structure to store informations
|
||||||
* about current session
|
* about current session
|
||||||
*/
|
*/
|
||||||
var profile={};
|
var profile = {};
|
||||||
profile.username=null;
|
profile.username = null;
|
||||||
profile.projectname=null;
|
profile.projectname = null;
|
||||||
var token=null;
|
var token = null;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @returns {boolean} Return true if a cookie is found (and load it in profile) false else
|
* @returns {boolean} Return true if a cookie is found (and load it in profile) false else
|
||||||
*/
|
*/
|
||||||
var isAlreadyLogin=function(){
|
var isAlreadyLogin = function () {
|
||||||
|
|
||||||
// Load cookies
|
// Load cookies
|
||||||
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_1');
|
var tokenPart_1InCookie = $cookies.getObject('token.part_1');
|
||||||
|
|
||||||
|
|
||||||
// Check if cookie is defined
|
// Check if cookie is defined
|
||||||
if(typeof profileInCookie !== 'undefined'
|
if (typeof profileInCookie !== 'undefined'
|
||||||
&& typeof tokenPart_0InCookie !== 'undefined'
|
&& typeof tokenPart_0InCookie !== 'undefined'
|
||||||
&& typeof tokenPart_1InCookie !== 'undefined'
|
&& typeof tokenPart_1InCookie !== 'undefined'
|
||||||
){
|
) {
|
||||||
|
|
||||||
//if(token!==null){
|
//if(token!==null){
|
||||||
// If yes, put it into variables
|
// If yes, put it into variables
|
||||||
angular.extend(profile, profileInCookie);
|
angular.extend(profile, profileInCookie);
|
||||||
token=tokenPart_0InCookie+tokenPart_1InCookie;
|
token = tokenPart_0InCookie + tokenPart_1InCookie;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Return I'm Login
|
// Return I'm Login
|
||||||
|
@ -42,26 +42,26 @@ mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http,
|
||||||
|
|
||||||
// Return I'm not Login
|
// Return I'm not Login
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Destroy profile cookies
|
* Destroy profile cookies
|
||||||
*/
|
*/
|
||||||
var logout=function(){
|
var logout = function () {
|
||||||
$cookies.remove('profile');
|
$cookies.remove('profile');
|
||||||
$cookies.remove('token.part_0');
|
$cookies.remove('token.part_0');
|
||||||
$cookies.remove('token.part_1');
|
$cookies.remove('token.part_1');
|
||||||
token=null;
|
token = null;
|
||||||
profile.username=null;
|
profile.username = null;
|
||||||
profile.projectname=null;
|
profile.projectname = null;
|
||||||
|
|
||||||
// Reload Page
|
// Reload Page
|
||||||
//location.reload();
|
//location.reload();
|
||||||
$rootScope.$broadcast("logoutEvent");
|
$rootScope.$broadcast("logoutEvent");
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,23 +70,23 @@ mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http,
|
||||||
* @param {boolean} to check if the request is send or not
|
* @param {boolean} to check if the request is send or not
|
||||||
* @returns {requestParserResult} Formated data
|
* @returns {requestParserResult} Formated data
|
||||||
*/
|
*/
|
||||||
var parseLoginAnswer=function(response, failedToSendRequest){
|
var parseLoginAnswer = function (response, failedToSendRequest) {
|
||||||
|
|
||||||
// Defined return object
|
// Defined return object
|
||||||
var requestParserResult={};
|
var requestParserResult = {};
|
||||||
requestParserResult.status=1;
|
requestParserResult.status = 1;
|
||||||
requestParserResult.failReason=null;
|
requestParserResult.failReason = null;
|
||||||
|
|
||||||
if (typeof response.data.token !== 'undefined') {
|
if (typeof response.data.token !== 'undefined') {
|
||||||
// Set status code
|
// Set status code
|
||||||
requestParserResult.status=0;
|
requestParserResult.status = 0;
|
||||||
|
|
||||||
// Find the middle of the token to split it
|
// 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);
|
||||||
|
|
||||||
// Create expire date (cookie expire in 55 mins)
|
// Create expire date (cookie expire in 55 mins)
|
||||||
var expireDate=new Date();
|
var expireDate = new Date();
|
||||||
expireDate.setMinutes(expireDate.getMinutes()+55);
|
expireDate.setMinutes(expireDate.getMinutes() + 55);
|
||||||
|
|
||||||
// Save profile
|
// Save profile
|
||||||
$cookies.putObject('profile', profile, {'expires': expireDate});
|
$cookies.putObject('profile', profile, {'expires': expireDate});
|
||||||
|
@ -96,14 +96,12 @@ mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http,
|
||||||
$cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length), {'expires': expireDate});
|
$cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length), {'expires': expireDate});
|
||||||
|
|
||||||
// Put token in var
|
// Put token in var
|
||||||
token=response.data.token;
|
token = response.data.token;
|
||||||
|
|
||||||
}
|
} else if (failedToSendRequest) {
|
||||||
else if(failedToSendRequest){
|
requestParserResult.failReason = "Failed to send request";
|
||||||
requestParserResult.failReason="Failed to send request";
|
} else {
|
||||||
}
|
requestParserResult.failReason = "Please check your username, password and project name !";
|
||||||
else{
|
|
||||||
requestParserResult.failReason="Please check your username, password and project name !";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,19 +118,19 @@ mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http,
|
||||||
* @param {string} projectname The user project name
|
* @param {string} projectname The user project name
|
||||||
* @param {function} function to call when data is avalaible
|
* @param {function} function to call when data is avalaible
|
||||||
*/
|
*/
|
||||||
var login=function(username, password,projectname,callback){
|
var login = function (username, password, projectname, callback) {
|
||||||
|
|
||||||
// Set profile information (early)
|
// Set profile information (early)
|
||||||
profile.username=username;
|
profile.username = username;
|
||||||
profile.projectname=projectname;
|
profile.projectname = projectname;
|
||||||
|
|
||||||
var result=$http.post('../server/index.php',
|
var result = $http.post('../server/index.php',
|
||||||
$.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
|
$.param({"task": "Authenticate", "user": username, "password": password, "project": projectname}));
|
||||||
|
|
||||||
// Wait and handle the response
|
// Wait and handle the response
|
||||||
result.then(function (response){
|
result.then(function (response) {
|
||||||
callback(parseLoginAnswer(response, false));
|
callback(parseLoginAnswer(response, false));
|
||||||
},function(response){
|
}, function (response) {
|
||||||
callback(parseLoginAnswer(response, true));
|
callback(parseLoginAnswer(response, true));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -144,16 +142,16 @@ mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http,
|
||||||
/*
|
/*
|
||||||
* Get the profile
|
* Get the profile
|
||||||
*/
|
*/
|
||||||
var getProfile=function(){
|
var getProfile = function () {
|
||||||
return profile;
|
return profile;
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the token
|
* Get the token
|
||||||
*/
|
*/
|
||||||
var getToken=function(){
|
var getToken = function () {
|
||||||
return token;
|
return token;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,9 +160,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http,
|
||||||
login: login,
|
login: login,
|
||||||
getProfile: getProfile,
|
getProfile: getProfile,
|
||||||
isAlreadyLogin: isAlreadyLogin,
|
isAlreadyLogin: isAlreadyLogin,
|
||||||
logout:logout,
|
logout: logout,
|
||||||
getToken:getToken
|
getToken: getToken
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue