1
0
mirror of https://github.com/Foltik/Shimapan synced 2025-01-05 15:58:03 -05:00

Move login/register redirect to AuthService

This commit is contained in:
Jack 2017-10-14 16:31:41 -04:00
parent a1ffcfc395
commit 0d2239d4e0
Signed by: foltik
GPG Key ID: 303F88F996E95541
5 changed files with 5 additions and 11 deletions

View File

@ -37,10 +37,12 @@ angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', functi
data: user
}).then(function(res) {
saveToken(res.data.token);
$window.location.href = '/home';
})
};
this.logout = function() {
$window.localStorage.removeItem('shimapan-token');
$window.location.href = '/';
};
this.isLoggedIn = function() {
var payload = decodeToken(getToken());
@ -61,6 +63,7 @@ angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', functi
data: user
}).then(function(res) {
saveToken(res.data.token);
$window.location.href = '/home';
});
};

View File

@ -4,11 +4,6 @@ angular.module('NavCtrl', ['AuthSvc']).controller('NavController', ['$scope', '$
$scope.currentScope = AuthService.currentScope();
$scope.logout = AuthService.logout;
$scope.goLogout = function() {
$scope.logout();
$window.location.href = '/';
};
$scope.hasPermission = function(permission) {
if (!$scope.currentScope) return false;
return $scope.currentScope.indexOf(permission) !== -1;

View File

@ -5,9 +5,7 @@ angular.module('LoginComp', ['AuthSvc']).component('loginComponent', {
AuthService.login({
username: $scope.username,
password: $scope.password
}).then(function () {
alert('Logged In');
});
}
};
}]
});

View File

@ -6,8 +6,6 @@ angular.module('RegisterComp', ['AuthSvc']).component('registerComponent', {
username: $scope.username,
password: $scope.password,
invite: $scope.invite
}).then(function () {
alert('Registered');
});
};
}]

View File

@ -27,7 +27,7 @@
<li><a href="/panel/invites" ng-class="{active: $state.$current.name=='/panel/invites'}">Invites</a></li>
<li ng-hide="!hasPermission('users.view')"><a href="/panel/users" ng-class="{active: $state.$current.name=='/panel/users'}">Users</a></li>
<li><a href="/panel/stats" ng-class="{active: $state.$current.name=='/panel/stats'}">Statistics</a></li>
<li><a href="" ng-click="goLogout()">Logout</a></li>
<li><a href="" ng-click="logout()">Logout</a></li>
</ul>
</div>
<div class="content isOpen" ng-class="{isOpen: open}">