我想知道一个人如何会通过限制访问任何和所有的意见去(除登录/注册)的意见,直到问题的用户登录英寸限制访问的意见,直到登录
然后,我会用$ http.post将表单内容发布到我的后端,如果用户没有问题登录,则重定向到短划线视图。
我想知道一个人如何会通过限制访问任何和所有的意见去(除登录/注册)的意见,直到问题的用户登录英寸限制访问的意见,直到登录
然后,我会用$ http.post将表单内容发布到我的后端,如果用户没有问题登录,则重定向到短划线视图。
我会建议使用$stateChangeStart
事件侦听修改意见,并做了检查,如果用户登录或没有。由于Ionic使用ui-router
而不是Angular的默认$route
,因此您需要使用ui-router
的API。
https://angular-ui.github.io/ui-router/site/#/api/ui.router.state。$状态
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
event.preventDefault();
// Check if user is logged in here, if not redirect state
if (!User.valid) {
$state.go('home.login');
}
});
使用声明的国家的决心功能要求你添加一个决心要保护的任何途径。使用事件侦听器可以让你在一个地方处理它。
可以解决重定向如果没有登录
config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/restricted',{
'templateUrl': //some template url,
//Etc...
//then ...
'resolve': {
'onEnter': function (redirectService, authService) {
if (!!!authService.isLogged()) {
redirectService.redirectNotlogged();
}
}
}
});
}]);
关注此链接我认为这将帮助你:https://medium.com/opinionated-angularjs/techniques-for-authentication-in-angularjs-applications-7bbf0346acec – 2014-09-01 16:41:37