blob: 1a89563ac256efb54a1308b04d7a4aa622e93488 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/**
* 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 {Identity} The Identity service
*/
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});
}
// Manager logout event
$scope.$on('logoutEvent', function(){
Identity.logout();
$('#loginModal').modal({backdrop: 'static', keyboard: false});
});
// Hide loading button and message alert
$('#loadingLoginButton').hide();
$('#failedToLoginAlert').hide();
// Defined function for login
$scope.loginAction=function(){
// Begin login state for template
$('#loginButton').hide();
$('#loadingLoginButton').show();
$('#failedToLoginAlert').hide();
// 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();
}
// Try to login
Identity.login(username, password, projectname, responseCallback);
};
}]);
|