istic-openstack/client/js/controllers/login.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-02-03 18:57:20 +01:00
/**
2016-02-06 12:10:04 +01:00
* The login controler
* @param {$scope} $scope The $scope angular service
* @param {$sce} $sce The $sce angular service
* @param {$http} $http The $http angular service
2016-02-10 21:45:52 +01:00
* @param {Identity} The Identity service
2016-02-06 12:10:04 +01:00
2016-02-03 18:57:20 +01:00
*/
mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity)
{
2016-03-21 06:47:01 +01:00
// Check for login and define default states
if(!Identity.isAlreadyLogin()){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
}
2016-02-24 15:02:14 +01:00
2016-03-21 06:47:01 +01:00
// Manager logout event
$scope.$on('logoutEvent', function(){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
});
2016-02-24 15:02:14 +01:00
2016-03-02 17:41:04 +01:00
2016-02-24 15:02:14 +01:00
// Hide loading button and message alert
$('#loadingLoginButton').hide();
$('#failedToLoginAlert').hide();
2016-02-05 19:35:38 +01:00
2016-02-24 15:02:14 +01:00
// Defined function for login
2016-02-17 14:01:13 +01:00
$scope.loginAction=function(){
2016-02-10 21:45:52 +01:00
// Begin login state for template
2016-02-05 17:47:53 +01:00
$('#loginButton').hide();
$('#loadingLoginButton').show();
$('#failedToLoginAlert').hide();
2016-02-10 21:45:52 +01:00
// Get data from templates
2016-02-05 19:35:38 +01:00
var username=$("#loginFormUsername").val();
var password=$("#loginFormPassword").val();
var projectname=$("#loginFormProjectname").val();
2016-02-10 21:45:52 +01:00
// Function to call to handle result
var responseCallback=function(response){
2016-02-10 19:27:28 +01:00
if(response.status!==0){
2016-02-10 21:45:52 +01:00
// Set reason of fail
$scope.failReason=response.failReason;
// Display the error
$('#failedToLoginAlert').show();
}
else {
2016-02-10 21:45:52 +01:00
// Else the user is online !
2016-02-10 17:55:13 +01:00
$('#loginModal').modal('hide');
}
2016-02-05 17:47:53 +01:00
// Reset button state
$('#loginButton').show();
2016-02-10 21:45:52 +01:00
$('#loadingLoginButton').hide();
}
// Try to login
Identity.login(username, password, projectname, responseCallback);
2016-02-17 14:01:13 +01:00
};
2016-02-10 21:45:52 +01:00
2016-02-05 19:35:38 +01:00
}]);