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:
parent
a1ffcfc395
commit
0d2239d4e0
@ -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';
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -5,9 +5,7 @@ angular.module('LoginComp', ['AuthSvc']).component('loginComponent', {
|
||||
AuthService.login({
|
||||
username: $scope.username,
|
||||
password: $scope.password
|
||||
}).then(function () {
|
||||
alert('Logged In');
|
||||
});
|
||||
}
|
||||
};
|
||||
}]
|
||||
});
|
@ -6,8 +6,6 @@ angular.module('RegisterComp', ['AuthSvc']).component('registerComponent', {
|
||||
username: $scope.username,
|
||||
password: $scope.password,
|
||||
invite: $scope.invite
|
||||
}).then(function () {
|
||||
alert('Registered');
|
||||
});
|
||||
};
|
||||
}]
|
||||
|
@ -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}">
|
||||
|
Loading…
Reference in New Issue
Block a user