用户登录失败后设计重定向 [英] Devise redirect after users fail signin
问题描述
我知道有一个关于它的维基页面,但由于我对Rails很新,我在理解该页面时遇到很多困难。
I know there is a wiki page about it, but since I'm very new to Rails I am having lot of difficulties in understanding that page.
我不得不为我的用户重写注册控制器。当用户登录失败时,我希望他被重定向到我的自定义登录页面。但应用程序将其发送到宝石内的登录页面。
I had to override registration controller for my user. When user fails to signin I want him to be redirected to my custom signin page. But the application send him to the signin page inside the gem.
我该如何完成?
我有多个模型,每个模型都有一个不同的登录页面。 如何设置每个模型的范围?
class CustomFailure < Devise::FailureApp
def redirect_url
#return super unless [:worker, :employer, :user].include?(scope) #make it specific to a scope
new_user_session_url(:subdomain => 'secure')
end
# You need to override respond to eliminate recall
def respond
if http_auth?
http_auth
else
redirect
end
end
end
Devise是一个强大的宝石,但一些wiki页面不认为可能有很多新的程序员
Devise is a powerful gem but some wiki pages don't consider that there can be lots of new programmers
推荐答案
我直接在 / lib
中找到我的身份验证失败课程。
I have my auth failure over-ride class in /lib
directly.
这是一个裸机版本,显示如何处理用户的不同范围。
Here's a bare-bones version that shows how to handle different scopes for users.
class MyAuthFailure < Devise::FailureApp
# add different cases here for diff scopes.
def redirect_url
if warden_options[:scope] == :user
root_path
elsif warden_options[:scope] == :admin
admin_root_path
end
end
# You need to override respond to eliminate recall
def respond
if http_auth?
http_auth
else
redirect
end
end
end
你可以把这个类放在 /lib/my_auth_failure.rb
这篇关于用户登录失败后设计重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!