Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class LoginComponent {
  3.  
  4.     constructor($mdToast, $rootScope, $location, $auth, $http, AuthFactory) {
  5.         this.$mdToast = $mdToast;
  6.         this.$rootScope = $rootScope;
  7.         this.$location = $location;
  8.         this.$auth = $auth;
  9.         this.$http = $http;
  10.         this.AuthFactory = AuthFactory;
  11.  
  12.         this.password = '';
  13.         this.email = '';
  14.         this.pageClass = 'page-home';
  15.         this.users = [];
  16.         this.error = null;
  17.  
  18.         this.loginError = false;
  19.         this.loginErrorText = '';
  20.     }
  21.  
  22.     login () {
  23.  
  24.         var credentials = {
  25.             email: this.email,
  26.             password: this.password
  27.         };
  28.  
  29.         this.$authService.login(credentials).then(function() {
  30.             return $http.get('http://localhost:8000/api/me').error(function () {
  31.                 alert('Service is unavailable');
  32.             });
  33.         }, function(error) {
  34.             console.log(error);
  35.             this.loginError = true;
  36.             //$scope.loginErrorText = error.data.error;
  37.  
  38.             console.error('not auth');
  39.         }).then(function(response) {
  40.             console.log(response);
  41.             var user = JSON.stringify(response.data.user);
  42.  
  43.             this.AuthFactory.setUser(user);
  44.             this.AuthFactory.setAuthenticated(true);
  45.  
  46.         });
  47.     };
  48.  
  49.     getUsers () {
  50.  
  51.         this.$http.get('api/users').success(function(users) {
  52.             this.users = users;
  53.         }).error(function(error) {
  54.             this.error = error;
  55.         });
  56.     };
  57.  
  58.     logout () {
  59.         this.$auth.logout().then(function() {
  60.             this.AuthFactory.setUser(null);
  61.             this.AuthFactory.setAuthenticated(false);
  62.         });
  63.     };
  64.  
  65.     showSimpleToast () {
  66.         var toast = this.$mdToast
  67.             .simple()
  68.             .action('Ok')
  69.             .hideDelay(5000)
  70.             .position('top left')
  71.             .textContent('Login or Sign In!');
  72.  
  73.         this.$mdToast.show(toast);
  74.     };
  75.  
  76.     redirectToSignIn () {
  77.  
  78.         this.$location.path('/signin');
  79.  
  80.     };
  81. }
  82. LoginComponent.$inject = ['$mdToast', '$rootScope', '$location', '$auth', '$http', 'AuthFactory'];
  83.  
  84. app.component('login', {
  85.     templateUrl: '/js/components/login/Directives/login.html',
  86.     controller: 'LoginCtrl'
  87. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement