基于用户登录类型重定向页面 [英] Redirect page based on userlogin type

查看:97
本文介绍了基于用户登录类型重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户成功登录后,我希望页面重定向到 / person / personCreate ,并且将以下代码添加到 Config.groovy

  grails.plugin.springsecurity.successHandler.defaultTargetUrl =/ person / personCreate

现在,我有两种类型的用户 SuperHuman 人类。如果usertype是 SuperHuman 我希望页面被重定向 / person / superHumanPage ,否则如果用户类型是 Human 我想将页面重定向到 / person / personCreate



更新

i.stack.imgur.com/VeCyc.pngalt =在这里输入图片描述>

解决方案

根据 User 类的属性区分超人类和普通人类。当你使用spring安全性时,一个更自然的方式就是将这些角色定义为角色(AKA权威)并将它们分配给每个用户。



然后你可以执行你的登录后重定向操作,如下所示:



$ p $ import grails.plugin.springsecurity.SpringSecurityUtils

class PersonController {
$ b $ def personCreate(){
if(SpringSecurityUtils.ifAllGranted('SUPER_HUMAN')){
redirect action:'superHumanHome'
} else {
redirect action:'humanHome'
}
}

def superHumanHome(){
//显示超级人物的主页

$ b $ def humanHome(){
//显示人的主页
}
}

顺便说一句,在你的问题中,你说 personCreate 是应该处理重定向逻辑的动作,这也是人类的行为应该重定向到。这将为人类创造一个无限循环的重定向,这就是为什么我将人类重定向到上述控制器中的不同动作。


Upon successful user login i want the page to redirect to /person/personCreate and it did work after adding the following code to Config.groovy.

grails.plugin.springsecurity.successHandler.defaultTargetUrl = "/person/personCreate"

Now, i have two types of Users SuperHuman and Human. If the usertype is SuperHuman i want the page to be redirected /person/superHumanPage or else if the user type is Human i want the page to be redirected to /person/personCreate

How can i get this done ?

update

解决方案

It seems that you're distinguishing between super humans and regular humans based on an attribute of the User class. As you're using spring security, a much more natural way to make this distinction is to define these as roles (AKA authorities) and assign them to each user as appropriate.

You can then implement your post-login redirection action like this:

import grails.plugin.springsecurity.SpringSecurityUtils

class PersonController {

  def personCreate() {
    if (SpringSecurityUtils.ifAllGranted('SUPER_HUMAN')) {
      redirect action: 'superHumanHome'  
    } else {
      redirect action: 'humanHome'
    }
  }

  def superHumanHome() {
    // show the super human's home page
  }

  def humanHome() {
    // show the human's home page
  }
}

By the way, in your question, you said that personCreate is the action that should handle the redirection logic, and this is also that action that human's should be redirected to. This will create an infinite loop of redirection for human's, which is why I've redirected humans to a different action in the controller above.

这篇关于基于用户登录类型重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆