Advertisement
Guest User

Untitled

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