istic-openstack/client/js/controllers/login.js
manzerbredes bd81674a85 Add doc
2016-02-06 12:10:04 +01:00

60 lines
1.8 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','$http', 'sharedProfile', function ($scope,$sce, $http, sharedProfile)
{
// 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.request.login($http,username, password, projectname);
result.then(function (response){
// Parser result
var requestResultObject=identity.requestParser.parseLoginAnswer(response);
// Check for error
if(requestResultObject.status!==0){
//alert(result.data)
$('#failedToLoginAlert').show();
}
else {
$('#loginModal').modal('hide');
sharedProfile.username=username;
sharedProfile.projectname=projectname;
}
// Reset button state
$('#loginButton').show();
$('#loadingLoginButton').hide();
},function(response){
$('#failedToLoginAlert').show();
// Reset button state
$('#loginButton').show();
$('#loadingLoginButton').hide();
});
});
}]);