login.controller.js
2.81 KB
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
66
67
68
69
70
71
(function() {
'use strict'
angular.module('acufuel')
.controller('LoginController', [ '$scope', '$filter', '$rootScope', '$state','$location', 'LoginService', LoginController]);
function LoginController($scope, $filter, $rootScope, $state,$location, LoginService) {
$scope.data = {};
$scope.data.username = '';
$scope.data.password = '';
$scope.count = 0;
var loginData;
localStorage.removeItem('requiredChangePwd');
if($location.$$search && $location.$$search.tmppwd){
$scope.data.username = $location.$$search.email;
$scope.data.password = $location.$$search.tmppwd;
localStorage.setItem('requiredChangePwd', "Y");
}
$scope.submitLogin = function() {
loginData = "username=" + $scope.data.username + "&password=" + $scope.data.password;
if ($scope.data.username !== '' && $scope.data.password !== '' && $scope.data.username !== undefined && $scope.data.password !== undefined) {
if ($scope.count === 0) {
$scope.count++
LoginService.loginUser(loginData).then(function(result) {
var reqPwdChng = localStorage.getItem("requiredChangePwd");
if(result.status == 200){
if (reqPwdChng && reqPwdChng == "Y") {
$state.go('resetPassword');
} else {
LoginService.authenticate().then(function(result){
// console.log("==usertime from api===",result)
window.localStorage.setItem("userTime", JSON.stringify(result.userProfile.userTimeZone));
var currentUserDetail = JSON.parse(window.localStorage.getItem("currentUser"));
if(currentUserDetail.type === 'ADDITIONAL'){
var email = $scope.data.username;
//console.log("hi",email)
LoginService.getAdditionalAccess(email).then(function(result){
// console.log("getaccess",result)
window.localStorage.setItem("EPDAccess", JSON.stringify(result.allowEpd));
window.localStorage.setItem("FMAAccess", JSON.stringify(result.allowFma));
})
}
})
}
}else{
toastr.error('Username or password incorrect.', {
closeButton: true
});
$scope.count = 0;
}
})
}
}else{
toastr.error('Please enter username & password.', {
closeButton: true
})
}
}
}
})();