Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. $rootScope.systemMessage = data[0].Value;
  2. $scope.message = $rootScope.systemMessage;
  3. $rootScope.systemStatus = data[1].Value;
  4. }
  5. else
  6. {
  7. $rootScope.systemMessage = data[0].Value;
  8. $scope.message = $rootScope.systemMessage;
  9. $rootScope.systemStatus = data[1].Value;
  10. executeController();
  11. }
  12. },
  13. function(error){
  14. });
  15.  
  16. function executeController()
  17. {
  18. //////////////////////////////////////////////////////////////////////////////
  19. //Initial Information
  20. $scope.message = ($rootScope.systemMessage == "" ? "Welcome to Time Entry." : $rootScope.systemMessage);
  21. $scope.username = "";
  22. $scope.password = "";
  23. $scope.returnedData = {};
  24. $scope.userAlreadyLoggedIn = false;
  25. $scope.showModal = false;
  26.  
  27. if(!loggedInUser.getProfile().init)
  28. {
  29. if(!loggedInUser.getProfile().errors.length)
  30. {
  31. $state.go('home.main');
  32. }
  33. else
  34. {
  35. $scope.message = loggedInUser.getProfile().errors[0].message;
  36. }
  37. }
  38. /////////////////////////////////////////////////////////////////////////////////
  39. //Function: login()
  40. //Upon the user submisssion, perform the service call to build the user/employee's information for usage throughout the application.
  41. $scope.login = function()
  42. {
  43. var data = {
  44. "userName": $scope.username,
  45. "password": $scope.password,
  46. "browserString": navigator.appName
  47. }
  48. $http({
  49. method: 'post',
  50. url: 'http://10.1.150.174:8002/TimeEntry.svc/Login',
  51. headers: {'Content-Type':'application/json; charset=UTF-8; charset-uf8'},
  52. data: data
  53. })
  54. .success(function(data, status, headers, config) {
  55. $scope.returnedData = data;
  56. evaluateSuccessfulRetrieval();
  57. })
  58. .error(function(data, status, headers, config) {
  59. $scope.message = "Oops, there has been issue.";
  60. });
  61.  
  62. }
  63.  
  64. /////////////////////////////////////////////////////////////////////////////////
  65. //Function: evaluateSuccessfulRetrieval(data)
  66. //Takes the information and evaluates for any errors that may have been returned.
  67. function evaluateSuccessfulRetrieval()
  68. {
  69.  
  70. if($scope.returnedData.errors.length > 0)
  71. handleReturnedError($scope.returnedData.errors);
  72. else
  73. {
  74. $cookieStore.put("FunStuff", $scope.returnedData.auth);
  75. loggedInUser.setProfile($scope.returnedData);
  76. $state.go('home.main');
  77. }
  78.  
  79. }
  80.  
  81. /////////////////////////////////////////////////////////////////////////////////
  82. //Function: handleReturnedError(errors)
  83. //Handle any returned errors from the service call.
  84. function handleReturnedError(errors)
  85. {
  86. if(errors[0].code != 2)
  87. $scope.message = errors[0].message;
  88. else
  89. handleUserAlreadyLoggedIn();
  90. }
  91.  
  92. /////////////////////////////////////////////////////////////////////////////////
  93. //Function: handleUserAlreadyLoggedIn()
  94. //Display the modal and remove the ability of the user to access the form elements.
  95. function handleUserAlreadyLoggedIn()
  96. {
  97. $scope.userAlreadyLoggedIn = true;
  98. $scope.showModal = true;
  99. }
  100.  
  101. /////////////////////////////////////////////////////////////////////////////////
  102. //Function: handleUserAlreadyLoggedIn()
  103. //Handles the exception when a user is logged in elsewhere ro their session is still active.
  104. $scope.logout = function(code)
  105. {
  106. $scope.showModal = false;
  107.  
  108. if(code == '2')
  109. logOutOtherLocation();
  110. else
  111. $scope.userAlreadyLoggedIn = false;
  112. }
  113.  
  114. /////////////////////////////////////////////////////////////////////////////////
  115. //Function: logOutOtherLocation()
  116. //Log out the user's other session and proceed to log in this session.
  117. function logOutOtherLocation()
  118. {
  119. var logoutdata = {
  120. "Auth": "",
  121. "EmployeeID": $scope.username,
  122. "LogoutType": "2"
  123. }
  124.  
  125. Logout.logout(logoutdata)
  126. .then(function(data){
  127. $scope.login();
  128. },
  129. function(error){
  130. $scope.message = "Oops, there has been issue.";
  131. $scope.userAlreadyLoggedIn = false;
  132. });
  133. }
  134. }
  135.  
  136.  
  137. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement