0

我正在尝试访问用户登录的条件,如果他/她的帐户被停用,他/她应该被重定向回登录页面并显示一条消息我正在尝试这样的事情

def after_sign_in_path_for(resource)
 if resource.group.slug == 'a'
   @u = User.find_by_email(resource.email)
   if @u.member.state_id == "someid"
     '/logout'
     flash[:notice]= "My message."
   else
     a_root_path
   end
 elsif resource.group.slug == 'b'
   b_root_path
 elsif resource.group.slug == 'c'
   c_root_path
 else
   new_user_session_path
 end

end

任何建议如何阻止用户登录并阻止该范围的所有其他路由?

4

2 回答 2

0

after_sign_in_path_for 方法的返回值应该是您要重定向到的 url。因此,您不需要自己调用 redirect_to。

if @u.member.state_id == "someid"
  flash[:notice]= "My message."
  '/logout'
else
  a_root_path
end

(未测试)

于 2013-01-09T06:25:50.437 回答
0

你为什么不注销用户。如下

def after_sign_in_path_for(resource)
 if resource.group.slug == 'a'
  @u = User.find_by_email(resource.email)
  if @u.member.state_id == "someid"
    sign_out resource
    '/users/sign_in' (or root_path based on your requirement)
    flash[:notice]= "My message."
  else
    a_root_path
  end
 elsif resource.group.slug == 'b'
  b_root_path
 elsif resource.group.slug == 'c'
  c_root_path
 else
  new_user_session_path
 end
于 2013-01-09T07:53:18.147 回答