Login Service complete !
This commit is contained in:
parent
0c98543594
commit
3f83cae417
6 changed files with 94 additions and 61 deletions
|
@ -73,6 +73,7 @@
|
|||
|
||||
<!-- Include services -->
|
||||
<script src="./js/services/Identity.js"></script>
|
||||
<script src="./js/services/Image.js"></script>
|
||||
|
||||
<!-- Include controller -->
|
||||
<script src="./js/controllers/login.js"></script>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* @param {$scope} $scope The $scope angular service
|
||||
* @param {$sce} $sce The $sce angular service
|
||||
* @param {$http} $http The $http angular service
|
||||
* @param {sharedProfile} sharedProfile The sharedProfile service
|
||||
* @param {Identity} The Identity service
|
||||
|
||||
*/
|
||||
mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity)
|
||||
|
@ -16,42 +16,39 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s
|
|||
|
||||
|
||||
$('#loginButton').click(function(){
|
||||
|
||||
// Begin login state for template
|
||||
$('#loginButton').hide();
|
||||
$('#loadingLoginButton').show();
|
||||
$('#failedToLoginAlert').hide();
|
||||
|
||||
// Get data from templates
|
||||
var username=$("#loginFormUsername").val();
|
||||
var password=$("#loginFormPassword").val();
|
||||
var projectname=$("#loginFormProjectname").val();
|
||||
|
||||
var result=Identity.login(username, password, projectname);
|
||||
|
||||
|
||||
result.then(function (response){
|
||||
// Parser result
|
||||
var response=Identity.getResponse();
|
||||
|
||||
// Check for error
|
||||
// Function to call to handle result
|
||||
var responseCallback=function(response){
|
||||
|
||||
if(response.status!==0){
|
||||
|
||||
// Set reason of fail
|
||||
$scope.failReason=response.failReason;
|
||||
|
||||
// Display the error
|
||||
$('#failedToLoginAlert').show();
|
||||
}
|
||||
else {
|
||||
// Else the user is online !
|
||||
$('#loginModal').modal('hide');
|
||||
}
|
||||
|
||||
// Reset button state
|
||||
$('#loginButton').show();
|
||||
$('#loadingLoginButton').hide();
|
||||
},function(response){
|
||||
$('#failedToLoginAlert').show();
|
||||
|
||||
// Reset button state
|
||||
$('#loginButton').show();
|
||||
$('#loadingLoginButton').hide();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
$('#loadingLoginButton').hide();
|
||||
}
|
||||
|
||||
// Try to login
|
||||
Identity.login(username, password, projectname, responseCallback);
|
||||
});
|
||||
|
||||
}]);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* The status controller
|
||||
*
|
||||
* @param {$scope} $scope The $scope service from angular
|
||||
* @param {sharedProfile} sharedProfile The sharedProfile build by ourself
|
||||
* @param {Identity} The Identity service
|
||||
*/
|
||||
mainApp.controller('statusCtrl', ['$scope','Identity', function ($scope, Identity)
|
||||
{
|
||||
|
|
|
@ -1,14 +1,42 @@
|
|||
|
||||
mainApp.factory('Identity',[ '$http', function($http){
|
||||
|
||||
/* Create profile structure */
|
||||
/* Create profile structure to store informations
|
||||
* about current session
|
||||
*/
|
||||
var profile={};
|
||||
profile.username="Undefined";
|
||||
profile.projectname="Undefined";
|
||||
profile.token="";
|
||||
profile.username=null;
|
||||
profile.projectname=null;
|
||||
profile.token=null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} response The response to parse
|
||||
* @param {boolean} to check if the request is send or not
|
||||
* @returns {requestParserResult} Formated data
|
||||
*/
|
||||
var parseLoginAnswer=function(response, failedToSendRequest){
|
||||
|
||||
var requestParserResult={};
|
||||
requestParserResult.status=1;
|
||||
requestParserResult.failReason=null;
|
||||
|
||||
if (typeof response.data.token !== 'undefined') {
|
||||
requestParserResult.status=0;
|
||||
profile.token=response.data.token;
|
||||
}
|
||||
else if(failedToSendRequest){
|
||||
requestParserResult.failReason="Failed to send request";
|
||||
}
|
||||
else{
|
||||
requestParserResult.failReason="Please check your username, password and project name !";
|
||||
}
|
||||
|
||||
return requestParserResult;
|
||||
};
|
||||
|
||||
|
||||
/* Will contain the result of the $http request */
|
||||
var $httpResponse;
|
||||
|
||||
/**
|
||||
* Function to connect to OpenStack
|
||||
|
@ -17,46 +45,28 @@ mainApp.factory('Identity',[ '$http', function($http){
|
|||
* @param {string} username The user name
|
||||
* @param {string} password The user password
|
||||
* @param {string} projectname The user project name
|
||||
* @returns {promise} The result of the request
|
||||
* @param {function} function to call when data is avalaible
|
||||
*/
|
||||
var login=function(username, password,projectname){
|
||||
var login=function(username, password,projectname, callback){
|
||||
|
||||
// Set profile information (early)
|
||||
profile.username=username;
|
||||
profile.projectname=projectname;
|
||||
|
||||
$httpResponse=$http.post('../server/index.php',
|
||||
var result=$http.post('../server/index.php',
|
||||
$.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
|
||||
return $httpResponse;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} response The response to parse
|
||||
* @returns {requestParserResult} Formated data
|
||||
*/
|
||||
var parseLoginAnswer=function(response){
|
||||
var requestParserResult={};
|
||||
|
||||
requestParserResult.status=0;
|
||||
requestParserResult.data=response.data;
|
||||
profile.token="Un Token";
|
||||
|
||||
// TODO
|
||||
|
||||
|
||||
return requestParserResult;
|
||||
};
|
||||
|
||||
|
||||
var getResponse=function(){
|
||||
return parseLoginAnswer($httpResponse);
|
||||
}
|
||||
|
||||
// Wait and handle the response
|
||||
result.then(function (response){
|
||||
callback(parseLoginAnswer(response), false);
|
||||
},function(response){
|
||||
callback(parseLoginAnswer(response), true)
|
||||
});
|
||||
};
|
||||
|
||||
// Return services objects
|
||||
return {
|
||||
login: login,
|
||||
getResponse: getResponse,
|
||||
profile: profile
|
||||
};
|
||||
|
||||
|
|
25
client/js/services/Image.js
Normal file
25
client/js/services/Image.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
|
||||
|
||||
var httpResponse;
|
||||
|
||||
var uploadImage=function(image){
|
||||
|
||||
};
|
||||
|
||||
var parseUploadImageRequest=function(){
|
||||
|
||||
};
|
||||
|
||||
var getResponse=function(){
|
||||
return parseUploadImageRequest(httpResponse);
|
||||
};
|
||||
|
||||
// Return services objects
|
||||
return {
|
||||
uploadImage: uploadImage,
|
||||
getResponse: getResponse
|
||||
};
|
||||
|
||||
|
||||
}]);
|
|
@ -33,9 +33,9 @@
|
|||
<div class="modal-footer">
|
||||
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->
|
||||
<button class="btn btn-lg btn-warning btn-block" id="loadingLoginButton"><span class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></span> Loading...</button>
|
||||
<div class="alert alert-danger text-center" role="alert" id="failedToLoginAlert">Failed to login</div>
|
||||
<div class="alert alert-danger text-center" role="alert" id="failedToLoginAlert"><b>Failed to login</b></b><br />{{ failReason }}</div>
|
||||
<a href="#" class="btn btn-lg btn-primary btn-block" id="loginButton" ng-click="processForm()">Login</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue