istic-openstack/client/js/controllers/login.js
2016-02-10 19:27:28 +01:00

57 lines
1.6 KiB
JavaScript

/**
* The login controler
* @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
*/
mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity)
{
// Define default states
$('#loginModal').modal({backdrop: 'static', keyboard: false});
$('#loadingLoginButton').hide();
$('#failedToLoginAlert').hide();
$('#loginButton').click(function(){
$('#loginButton').hide();
$('#loadingLoginButton').show();
$('#failedToLoginAlert').hide();
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
if(response.status!==0){
$('#failedToLoginAlert').show();
}
else {
$('#loginModal').modal('hide');
}
// Reset button state
$('#loginButton').show();
$('#loadingLoginButton').hide();
},function(response){
$('#failedToLoginAlert').show();
// Reset button state
$('#loginButton').show();
$('#loadingLoginButton').hide();
});
});
}]);