Blame view
app/partials/login/login.controller.js
3.02 KB
feacde5ff
|
1 2 3 4 |
(function() { 'use strict' angular.module('acufuel') |
b17e02c05
|
5 |
.controller('LoginController', [ '$scope', '$filter', '$rootScope', '$state','$location', 'LoginService', LoginController]); |
67d43a8c6
|
6 |
|
b17e02c05
|
7 |
function LoginController($scope, $filter, $rootScope, $state,$location, LoginService) { |
658bb9318
|
8 9 |
//for hiding console errors |
8356de6ed
|
10 |
/* window.onerror = function(message, url, lineNumber) { |
658bb9318
|
11 12 |
// maybe some handling? return true; // prevents browser error messages |
8356de6ed
|
13 |
};*/ |
658bb9318
|
14 |
|
f62f8940f
|
15 |
|
1b71872b2
|
16 |
$scope.data = {}; |
67d43a8c6
|
17 18 19 20 |
$scope.data.username = ''; $scope.data.password = ''; $scope.count = 0; var loginData; |
3b466beb3
|
21 |
localStorage.removeItem('requiredChangePwd'); |
b17e02c05
|
22 23 24 25 26 27 28 29 |
if($location.$$search && $location.$$search.tmppwd){ $scope.data.username = $location.$$search.email; $scope.data.password = $location.$$search.tmppwd; localStorage.setItem('requiredChangePwd', "Y"); } |
4bb02bb84
|
30 |
$scope.submitLogin = function() { |
67d43a8c6
|
31 32 33 |
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) { |
671643c9f
|
34 |
$scope.count++ |
67d43a8c6
|
35 |
LoginService.loginUser(loginData).then(function(result) { |
5fd0d0f40
|
36 |
var reqPwdChng = localStorage.getItem("requiredChangePwd"); |
67d43a8c6
|
37 |
if(result.status == 200){ |
5fd0d0f40
|
38 39 40 |
if (reqPwdChng && reqPwdChng == "Y") { $state.go('resetPassword'); } else { |
f62f8940f
|
41 |
LoginService.authenticate().then(function(result){ |
938f3037d
|
42 |
// console.log("==usertime from api===",result) |
9aea92263
|
43 44 |
window.localStorage.setItem("userTime", JSON.stringify(result.userProfile.userTimeZone)); |
f62f8940f
|
45 46 47 48 49 |
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){ |
9aea92263
|
50 |
// console.log("getaccess",result) |
f62f8940f
|
51 52 53 54 55 |
window.localStorage.setItem("EPDAccess", JSON.stringify(result.allowEpd)); window.localStorage.setItem("FMAAccess", JSON.stringify(result.allowFma)); }) } }) |
5fd0d0f40
|
56 |
} |
67d43a8c6
|
57 58 59 |
}else{ toastr.error('Username or password incorrect.', { closeButton: true |
f148ae490
|
60 61 |
}); $scope.count = 0; |
67d43a8c6
|
62 |
} |
5fd0d0f40
|
63 |
|
67d43a8c6
|
64 65 66 67 68 69 70 |
}) } }else{ toastr.error('Please enter username & password.', { closeButton: true }) } |
4bb02bb84
|
71 |
} |
feacde5ff
|
72 73 |
} })(); |