2016-02-03 16:59:04 +01:00
|
|
|
|
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
|
|
|
|
* @param {sharedProfile} sharedProfile The sharedProfile service
|
|
|
|
|
2016-02-03 18:57:20 +01:00
|
|
|
*/
|
2016-02-05 19:35:38 +01:00
|
|
|
mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', function ($scope,$sce, $http, sharedProfile)
|
2016-02-03 16:59:04 +01:00
|
|
|
{
|
2016-02-04 13:20:45 +01:00
|
|
|
// Define default states
|
|
|
|
$('#loginModal').modal({backdrop: 'static', keyboard: false});
|
|
|
|
$('#loadingLoginButton').hide();
|
|
|
|
$('#failedToLoginAlert').hide();
|
2016-02-05 19:35:38 +01:00
|
|
|
|
2016-02-03 16:59:04 +01:00
|
|
|
|
2016-02-04 13:20:45 +01:00
|
|
|
$('#loginButton').click(function(){
|
2016-02-05 17:47:53 +01:00
|
|
|
$('#loginButton').hide();
|
|
|
|
$('#loadingLoginButton').show();
|
|
|
|
$('#failedToLoginAlert').hide();
|
2016-02-03 16:59:04 +01:00
|
|
|
|
2016-02-05 19:35:38 +01:00
|
|
|
var username=$("#loginFormUsername").val();
|
|
|
|
var password=$("#loginFormPassword").val();
|
|
|
|
var projectname=$("#loginFormProjectname").val();
|
|
|
|
|
|
|
|
var result=identity.request.login($http,username, password, projectname);
|
2016-02-05 17:47:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
result.then(function (response){
|
|
|
|
// Parser result
|
|
|
|
var requestResultObject=identity.requestParser.parseLoginAnswer(response);
|
|
|
|
|
2016-02-04 13:20:45 +01:00
|
|
|
// Check for error
|
2016-02-05 17:47:53 +01:00
|
|
|
if(requestResultObject.status!==0){
|
|
|
|
//alert(result.data)
|
2016-02-04 13:20:45 +01:00
|
|
|
$('#failedToLoginAlert').show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#loginModal').modal('hide');
|
2016-02-05 19:35:38 +01:00
|
|
|
sharedProfile.username=username;
|
|
|
|
sharedProfile.projectname=projectname;
|
|
|
|
|
2016-02-04 13:20:45 +01:00
|
|
|
}
|
2016-02-05 17:47:53 +01:00
|
|
|
|
2016-02-04 13:20:45 +01:00
|
|
|
// Reset button state
|
2016-02-03 16:59:04 +01:00
|
|
|
$('#loginButton').show();
|
2016-02-04 13:20:45 +01:00
|
|
|
$('#loadingLoginButton').hide();
|
2016-02-05 17:47:53 +01:00
|
|
|
},function(response){
|
|
|
|
$('#failedToLoginAlert').show();
|
2016-02-03 17:16:36 +01:00
|
|
|
|
2016-02-05 17:47:53 +01:00
|
|
|
// Reset button state
|
|
|
|
$('#loginButton').show();
|
|
|
|
$('#loadingLoginButton').hide();
|
|
|
|
});
|
2016-02-05 19:35:38 +01:00
|
|
|
|
2016-02-05 17:47:53 +01:00
|
|
|
|
2016-02-03 16:59:04 +01:00
|
|
|
|
|
|
|
});
|
2016-02-05 19:35:38 +01:00
|
|
|
}]);
|