Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- app.controller('MainController', function($scope, $rootScope, $route, $routeParams, $location, $http) {
- $scope.$route = $route;
- $scope.$location = $location;
- $scope.$routeParams = $routeParams;
- $rootScope.variableTypes = ['int','double', 'string','boolean','var'];
- var user = JSON.parse(localStorage.getItem("UserLoggedIn"));
- if(user !== null) {
- $rootScope.isAuthenticated = true;
- $rootScope.userEmail = user.email;
- $rootScope.userRole = user.role;
- }
- $rootScope.loginError = '';
- $scope.login = function (user) {
- $http.post("http://localhost:8080/users/login",user).then(
- function successCallback(response) {
- $scope.response = response.data;
- $rootScope.isAuthenticated = true;
- $rootScope.userEmail = user.email;
- localStorage.setItem('UserLoggedIn', JSON.stringify({"email":user.email, "role":user.role}));
- $location.path('/home');
- $rootScope.error = '';
- },
- function errorCallback(response) {
- console.log(response.data.message);
- $rootScope.loginError = response.data.message;
- }
- );
- };
- $scope.logout = function () {
- $rootScope.isAuthenticated = false;
- $rootScope.userEmail = '';
- $rootScope.userRole = '';
- localStorage.removeItem('UserLoggedIn')
- $location.path('/login');
- };
- $scope.changePassword = function (password) {
- var user = {"email": $rootScope.userEmail, "password" : password};
- $http.put("http://localhost:8080/users/change-password", user).then(
- function successCallback(response) {
- $scope.response = response.data;
- $location.path('/home');
- $rootScope.error = '';
- },
- function errorCallback(response) {
- console.log(response.data.message);
- }
- );
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement