Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. twPublicApp.controller('PublicLoginCtrl', function ($scope, $http, LoginData, BrowserStorageService, $window, $location) {
  2. window.changeApiRoot('/api/');
  3.  
  4. $scope.username = '';
  5. $scope.password = '';
  6. $scope.remember = false;
  7. $scope.errorMessage = '';
  8. $scope.authenticating = false;
  9.  
  10. if (LoginData.get('SessionToken', null, true) !== null) {
  11. // Check if still has a valid session
  12. $scope.authenticating = true;
  13. LoginData.checkSession(LoginData.get('SessionToken'), LoginData.get('Location'))
  14. .success(function(data) {
  15. if (data.Result === true) {
  16. console.log('User looks to be already logged in... sending on');
  17. BrowserStorageService.changeStore('localStorage');
  18. LoginData.set(data);
  19.  
  20. //This is the line giving me problems. I've tried these two versions, and a few others, and nothing seems to work properly.
  21. //window.location.href = '/console#/status';
  22. $window.location = '/console#/status';
  23.  
  24. $scope.authenticating = false;
  25. } else {
  26. $scope.authenticating = false;
  27. LoginData.set({});
  28. }
  29. })
  30. .error(function(jqXHR, textStatus, errorThrown) {
  31. $scope.authenticating = false;
  32. LoginData.set({});
  33. });
  34. }
  35.  
  36. $scope.authenticate = function() {
  37. $scope.authenticating = true;
  38. LoginData.authenticate($scope.username, $scope.password, $scope.remember)
  39. .success(function(data) {
  40. if (data.Result === true) {
  41. if ($scope.remember) {
  42. BrowserStorageService.changeStore('localStorage');
  43. } else {
  44. BrowserStorageService.changeStore('sessionStorage');
  45. }
  46. LoginData.set(data);
  47.  
  48. //Interestingly, this line works perfectly.
  49. window.location.href = '/console#/status';
  50.  
  51. return;
  52. }
  53. $scope.authenticating = false;
  54. })
  55. .error(function(jqXHR, textStatus, errorThrown) {
  56. $scope.authenticating = false;
  57. });
  58. };
  59.  
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement