简体   繁体   English

如何限制登录用户在angular js的登录页面或注册页面中移动?

[英]how to restrict logged user to move on login page or signup page in angular js?

i have following code : 我有以下代码:

.run(function($rootScope, $location, Auth) {

    //Redirect to login if route requires auth and you're not logged in
    $rootScope.$on('$routeChangeStart', function(event, next) {

       Auth.isLoggedInAsync(function(loggedIn) {
        if (!loggedIn) {//when user is not logged in
          if ($location.path() == "/participant/signup" || $location.path() == "/researcher/signup" || $location.path() == "/participant/login" || $location.path() == "/researcher/login" || $location.path() == "/admin/login");

          else{
            $location.path('/homePage');
          }
        }
        else if(loggedIn){ //when user loged in
          if ($location.path() == "/participant/signup" || $location.path() == "/researcher/signup" || $location.path() == "/participant/login" || $location.path() == "/researcher/login" || $location.path() == "/admin/login"){
            event.preventDefault();
            //event.stopPropagation();
          }
        }
      });
    });
  })

i want to restrict logged user to move on login or signup page. 我想限制登录用户在登录或注册页面上移动。 the above code is not working please suggest me where i am doing wrong. 上面的代码不起作用,请建议我在哪里做错了。 if you have a good way to handle this please suggest? 如果您有解决此问题的好方法,请提出建议?

Define an interceptor to handle user status

angular.module('App').factory('authInterceptor', ['$location', 'Auth', function ($location, Auth) {

        var authInterceptorService = {};
        if (!Auth.isLoggedIn)
            $location.url('/login');

        return authInterceptorService;
    }]);

In App.js 在App.js中

angular.module('App').config(function ($httpProvider) {
    $httpProvider.interceptors.push('authInterceptorService');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果已经使用 Reactjs 登录,如何限制用户显示登录页面 - How to restrict user to display login page if already logged in using Reactjs 如果用户尚未登录Angular JS,则重定向到登录页面 - Redirect to a login page if the user is not yet logged in Angular JS 限制用户登录后重定向到登录页面,即使他按角度按浏览器的后退按钮? - restrict the redirection to login page once the user has already logged in even if he press the back button of browser in angular? 如果用户已登录,如何限制后退按钮,或直接在angularjs中访问登录页面 - if user is logged in, how to restrict the back button, or accessing the login page directly in angularjs Angular 2/4:如果用户已经登录,如何限制对登录路由的访问? - Angular 2/4: How to restrict access to Login Route if user is already logged in? 如何防止登录用户看到登录页面 - How to prevent logged in user to see login page 如何防止用户登录后看到登录页面? - How to prevent user from seeing login page after logged in? 如何防止用户在登录Vuejs后转到登录页面? - How to prevent user to go to login page after logged in in Vuejs? 在angular4中使用用户页面注册时如何更改主页的内容 - how to make the contents of home page to change when signUp with user page in angular4 我想在用户登录时限制页面路由 - I want to restrict the page routing when user is logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM