Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. 'use strict';
  2.  
  3. app.controller('MainController', function($scope, $rootScope, $route, $routeParams, $location, $http) {
  4. $scope.$route = $route;
  5. $scope.$location = $location;
  6. $scope.$routeParams = $routeParams;
  7.  
  8. $rootScope.variableTypes = ['int','double', 'string','boolean','var'];
  9.  
  10. var user = JSON.parse(localStorage.getItem("UserLoggedIn"));
  11. if(user !== null) {
  12. $rootScope.isAuthenticated = true;
  13. $rootScope.userEmail = user.email;
  14. $rootScope.userRole = user.role;
  15. }
  16. $rootScope.loginError = '';
  17.  
  18. $scope.login = function (user) {
  19. $http.post("http://localhost:8080/users/login",user).then(
  20. function successCallback(response) {
  21. $scope.response = response.data;
  22. $rootScope.isAuthenticated = true;
  23. $rootScope.userEmail = user.email;
  24. localStorage.setItem('UserLoggedIn', JSON.stringify({"email":user.email, "role":user.role}));
  25. $location.path('/home');
  26. $rootScope.error = '';
  27. },
  28. function errorCallback(response) {
  29. console.log(response.data.message);
  30. $rootScope.loginError = response.data.message;
  31. }
  32. );
  33. };
  34.  
  35. $scope.logout = function () {
  36. $rootScope.isAuthenticated = false;
  37. $rootScope.userEmail = '';
  38. $rootScope.userRole = '';
  39. localStorage.removeItem('UserLoggedIn')
  40. $location.path('/login');
  41. };
  42.  
  43. $scope.changePassword = function (password) {
  44. var user = {"email": $rootScope.userEmail, "password" : password};
  45. $http.put("http://localhost:8080/users/change-password", user).then(
  46. function successCallback(response) {
  47. $scope.response = response.data;
  48. $location.path('/home');
  49. $rootScope.error = '';
  50. },
  51. function errorCallback(response) {
  52. console.log(response.data.message);
  53. }
  54. );
  55. }
  56. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement