gpt4 book ai didi

ruby-on-rails - 使用 Devise 强制用户注销

转载 作者:行者123 更新时间:2023-12-02 21:40:24 27 4
gpt4 key购买 nike

我有一个 Controller 过滤器,如果用户的帐户过期,它应该注销用户,但我无法找到一种简单的方法来做到这一点。

我尝试过:

if user_signed_in? && current_user.status == 'expired'
redirect_to destroy_user_session_path
end

但是上面的方法不起作用,因为 Devise 想要在注销路径上执行 DELETE 操作,因此您不能只是重定向到它。

最佳答案

active_for_authentication?

在对每个请求中的用户进行身份验证后,Devise 通过调用 model.active_for_authentication? 来检查您的模型是否处于事件状态。该方法被其他设备模块覆盖。例如,:confirmable 会覆盖 .active_for_authentication?仅当您的模型得到确认时才返回 true。

您自己重写此方法,但如果这样做,请不要忘记调用 super:

def active_for_authentication?
super && special_condition_is_valid?
end

看看documentation了解更多详细信息和示例。这个doc也会对你有帮助。

关于ruby-on-rails - 使用 Devise 强制用户注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20559560/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com