Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LoginComponent {
- constructor($mdToast, $rootScope, $location, $auth, $http, AuthFactory) {
- this.$mdToast = $mdToast;
- this.$rootScope = $rootScope;
- this.$location = $location;
- this.$auth = $auth;
- this.$http = $http;
- this.AuthFactory = AuthFactory;
- this.password = 'pass';
- this.email = 'nostresss77@gmail.com';
- this.pageClass = 'page-home';
- this.users = [];
- this.error = null;
- this.loginError = false;
- this.loginErrorText = '';
- }
- login () {
- var credentials = {
- email: this.email,
- password: this.password
- };
- this.$authService.login(credentials).then(function() {
- return $http.get('http://localhost:8000/api/me').error(function () {
- alert('Service is unavailable');
- });
- }, function(error) {
- console.log(error);
- this.loginError = true;
- //$scope.loginErrorText = error.data.error;
- console.error('not auth');
- }).then(function(response) {
- console.log(response);
- var user = JSON.stringify(response.data.user);
- this.AuthFactory.setUser(user);
- this.AuthFactory.setAuthenticated(true);
- });
- };
- getUsers () {
- this.$http.get('api/users').success(function(users) {
- this.users = users;
- }).error(function(error) {
- this.error = error;
- });
- };
- logout () {
- this.$auth.logout().then(function() {
- this.AuthFactory.setUser(null);
- this.AuthFactory.setAuthenticated(false);
- });
- };
- showSimpleToast () {
- var toast = this.$mdToast
- .simple()
- .action('Ok')
- .hideDelay(5000)
- .position('top left')
- .textContent('Login or Sign In!');
- this.$mdToast.show(toast);
- };
- redirectToSignIn () {
- this.$location.path('/signin');
- };
- }
- LoginComponent.$inject = ['$mdToast', '$rootScope', '$location', '$auth', '$http', 'AuthFactory'];
- app.component('login', {
- templateUrl: '/js/components/login/Directives/login.html',
- controller: LoginComponent
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement