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

66 lines
2 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-04-16 22:06:18 +02:00
2016-02-03 18:57:20 +01:00
*/
2016-04-16 22:06:18 +02:00
mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', function ($scope, $sce, Identity)
{
// 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-04-16 22:06:18 +02: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-05 19:35:38 +01:00
2016-04-16 22:06:18 +02:00
// Hide loading button and message alert
$('#loadingLoginButton').hide();
2016-02-05 17:47:53 +01:00
$('#failedToLoginAlert').hide();
2016-02-05 19:35:38 +01:00
2016-04-16 22:06:18 +02:00
// Defined function for login
$scope.loginAction = function () {
2016-02-10 21:45:52 +01:00
2016-04-16 22:06:18 +02:00
// Begin login state for template
$('#loginButton').hide();
$('#loadingLoginButton').show();
$('#failedToLoginAlert').hide();
2016-02-10 21:45:52 +01:00
2016-04-16 22:06:18 +02:00
// Get data from templates
var username = $("#loginFormUsername").val();
var password = $("#loginFormPassword").val();
var projectname = $("#loginFormProjectname").val();
// 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();
}
2016-02-05 17:47:53 +01:00
2016-04-16 22:06:18 +02:00
// Try to login
Identity.login(username, password, projectname, responseCallback);
};
}]);