Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $rootScope.systemMessage = data[0].Value;
- $scope.message = $rootScope.systemMessage;
- $rootScope.systemStatus = data[1].Value;
- }
- else
- {
- $rootScope.systemMessage = data[0].Value;
- $scope.message = $rootScope.systemMessage;
- $rootScope.systemStatus = data[1].Value;
- executeController();
- }
- },
- function(error){
- });
- function executeController()
- {
- //////////////////////////////////////////////////////////////////////////////
- //Initial Information
- $scope.message = ($rootScope.systemMessage == "" ? "Welcome to Time Entry." : $rootScope.systemMessage);
- $scope.username = "";
- $scope.password = "";
- $scope.returnedData = {};
- $scope.userAlreadyLoggedIn = false;
- $scope.showModal = false;
- if(!loggedInUser.getProfile().init)
- {
- if(!loggedInUser.getProfile().errors.length)
- {
- $state.go('home.main');
- }
- else
- {
- $scope.message = loggedInUser.getProfile().errors[0].message;
- }
- }
- /////////////////////////////////////////////////////////////////////////////////
- //Function: login()
- //Upon the user submisssion, perform the service call to build the user/employee's information for usage throughout the application.
- $scope.login = function()
- {
- var data = {
- "userName": $scope.username,
- "password": $scope.password,
- "browserString": navigator.appName
- }
- $http({
- method: 'post',
- url: 'http://10.1.150.174:8002/TimeEntry.svc/Login',
- headers: {'Content-Type':'application/json; charset=UTF-8; charset-uf8'},
- data: data
- })
- .success(function(data, status, headers, config) {
- $scope.returnedData = data;
- evaluateSuccessfulRetrieval();
- })
- .error(function(data, status, headers, config) {
- $scope.message = "Oops, there has been issue.";
- });
- }
- /////////////////////////////////////////////////////////////////////////////////
- //Function: evaluateSuccessfulRetrieval(data)
- //Takes the information and evaluates for any errors that may have been returned.
- function evaluateSuccessfulRetrieval()
- {
- if($scope.returnedData.errors.length > 0)
- handleReturnedError($scope.returnedData.errors);
- else
- {
- $cookieStore.put("FunStuff", $scope.returnedData.auth);
- loggedInUser.setProfile($scope.returnedData);
- $state.go('home.main');
- }
- }
- /////////////////////////////////////////////////////////////////////////////////
- //Function: handleReturnedError(errors)
- //Handle any returned errors from the service call.
- function handleReturnedError(errors)
- {
- if(errors[0].code != 2)
- $scope.message = errors[0].message;
- else
- handleUserAlreadyLoggedIn();
- }
- /////////////////////////////////////////////////////////////////////////////////
- //Function: handleUserAlreadyLoggedIn()
- //Display the modal and remove the ability of the user to access the form elements.
- function handleUserAlreadyLoggedIn()
- {
- $scope.userAlreadyLoggedIn = true;
- $scope.showModal = true;
- }
- /////////////////////////////////////////////////////////////////////////////////
- //Function: handleUserAlreadyLoggedIn()
- //Handles the exception when a user is logged in elsewhere ro their session is still active.
- $scope.logout = function(code)
- {
- $scope.showModal = false;
- if(code == '2')
- logOutOtherLocation();
- else
- $scope.userAlreadyLoggedIn = false;
- }
- /////////////////////////////////////////////////////////////////////////////////
- //Function: logOutOtherLocation()
- //Log out the user's other session and proceed to log in this session.
- function logOutOtherLocation()
- {
- var logoutdata = {
- "Auth": "",
- "EmployeeID": $scope.username,
- "LogoutType": "2"
- }
- Logout.logout(logoutdata)
- .then(function(data){
- $scope.login();
- },
- function(error){
- $scope.message = "Oops, there has been issue.";
- $scope.userAlreadyLoggedIn = false;
- });
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement