Merge branch 'loic' into develop
This commit is contained in:
commit
8c6b1cecd3
6 changed files with 94 additions and 61 deletions
|
@ -73,6 +73,7 @@
|
||||||
|
|
||||||
<!-- Include services -->
|
<!-- Include services -->
|
||||||
<script src="./js/services/Identity.js"></script>
|
<script src="./js/services/Identity.js"></script>
|
||||||
|
<script src="./js/services/Image.js"></script>
|
||||||
|
|
||||||
<!-- Include controller -->
|
<!-- Include controller -->
|
||||||
<script src="./js/controllers/login.js"></script>
|
<script src="./js/controllers/login.js"></script>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @param {$scope} $scope The $scope angular service
|
* @param {$scope} $scope The $scope angular service
|
||||||
* @param {$sce} $sce The $sce angular service
|
* @param {$sce} $sce The $sce angular service
|
||||||
* @param {$http} $http The $http 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)
|
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(){
|
$('#loginButton').click(function(){
|
||||||
|
|
||||||
|
// Begin login state for template
|
||||||
$('#loginButton').hide();
|
$('#loginButton').hide();
|
||||||
$('#loadingLoginButton').show();
|
$('#loadingLoginButton').show();
|
||||||
$('#failedToLoginAlert').hide();
|
$('#failedToLoginAlert').hide();
|
||||||
|
|
||||||
|
// Get data from templates
|
||||||
var username=$("#loginFormUsername").val();
|
var username=$("#loginFormUsername").val();
|
||||||
var password=$("#loginFormPassword").val();
|
var password=$("#loginFormPassword").val();
|
||||||
var projectname=$("#loginFormProjectname").val();
|
var projectname=$("#loginFormProjectname").val();
|
||||||
|
|
||||||
var result=Identity.login(username, password, projectname);
|
// Function to call to handle result
|
||||||
|
var responseCallback=function(response){
|
||||||
|
|
||||||
result.then(function (response){
|
|
||||||
// Parser result
|
|
||||||
var response=Identity.getResponse();
|
|
||||||
|
|
||||||
// Check for error
|
|
||||||
if(response.status!==0){
|
if(response.status!==0){
|
||||||
|
// Set reason of fail
|
||||||
|
$scope.failReason=response.failReason;
|
||||||
|
|
||||||
|
// Display the error
|
||||||
$('#failedToLoginAlert').show();
|
$('#failedToLoginAlert').show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Else the user is online !
|
||||||
$('#loginModal').modal('hide');
|
$('#loginModal').modal('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset button state
|
// Reset button state
|
||||||
$('#loginButton').show();
|
$('#loginButton').show();
|
||||||
$('#loadingLoginButton').hide();
|
$('#loadingLoginButton').hide();
|
||||||
},function(response){
|
}
|
||||||
$('#failedToLoginAlert').show();
|
|
||||||
|
// Try to login
|
||||||
// Reset button state
|
Identity.login(username, password, projectname, responseCallback);
|
||||||
$('#loginButton').show();
|
});
|
||||||
$('#loadingLoginButton').hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* The status controller
|
* The status controller
|
||||||
*
|
*
|
||||||
* @param {$scope} $scope The $scope service from angular
|
* @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)
|
mainApp.controller('statusCtrl', ['$scope','Identity', function ($scope, Identity)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,14 +1,42 @@
|
||||||
|
|
||||||
mainApp.factory('Identity',[ '$http', function($http){
|
mainApp.factory('Identity',[ '$http', function($http){
|
||||||
|
|
||||||
/* Create profile structure */
|
/* Create profile structure to store informations
|
||||||
|
* about current session
|
||||||
|
*/
|
||||||
var profile={};
|
var profile={};
|
||||||
profile.username="Undefined";
|
profile.username=null;
|
||||||
profile.projectname="Undefined";
|
profile.projectname=null;
|
||||||
profile.token="";
|
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
|
* Function to connect to OpenStack
|
||||||
|
@ -17,46 +45,28 @@ mainApp.factory('Identity',[ '$http', function($http){
|
||||||
* @param {string} username The user name
|
* @param {string} username The user name
|
||||||
* @param {string} password The user password
|
* @param {string} password The user password
|
||||||
* @param {string} projectname The user project name
|
* @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.username=username;
|
||||||
profile.projectname=projectname;
|
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}));
|
$.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
|
||||||
return $httpResponse;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Wait and handle the response
|
||||||
/**
|
result.then(function (response){
|
||||||
*
|
callback(parseLoginAnswer(response), false);
|
||||||
* @param {string} response The response to parse
|
},function(response){
|
||||||
* @returns {requestParserResult} Formated data
|
callback(parseLoginAnswer(response), true)
|
||||||
*/
|
});
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Return services objects
|
// Return services objects
|
||||||
return {
|
return {
|
||||||
login: login,
|
login: login,
|
||||||
getResponse: getResponse,
|
|
||||||
profile: profile
|
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">
|
<div class="modal-footer">
|
||||||
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->
|
<!--<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>
|
<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>
|
<a href="#" class="btn btn-lg btn-primary btn-block" id="loginButton" ng-click="processForm()">Login</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue