gpt4 book ai didi

ruby-on-rails - 在 Ruby on Rails 中使用 Devise 插件进行身份验证限制

转载 作者:太空宇宙 更新时间:2023-11-03 17:57:08 25 4
gpt4 key购买 nike

有没有人使用过 Rails Devise 插件?因为在我的项目中,当用户输入用户名和密码时,我必须在另一个表中检查用户是否处于事件状态。有两个表,第一个是user,另一个是role_membershiprole_membership 表中有一列名为active_status。我必须检查 active_status = 1 否则用户无法登录系统。这里的任何人都知道如何配置 Devise 插件来检查另一个表中的值。我找到了一些教程,但所有教程都提到了在同一个表中检查字段。

谢谢

最佳答案

修改您的用户模型以包含两个额外的方法

  • active_for_authentication?
  • inactive_message

参见 http://pivotallabs.com/users/carl/blog/articles/1619-standup-3-21-2011-deactivating-users-in-devise (注意:它基于旧版本的设计,下面的代码应该可以工作)

class User
# check to see if a user is active or not and deny login if not
def active_for_authentication?
super && your_custom_logic
end

# flash message for the inactive users
def inactive_message
"Sorry, this account has been deactivated."
end
end

将 your_custom_logic 替换为您的特定代码以确定用户是否处于事件状态

附加链接:http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Authenticatable/

关于ruby-on-rails - 在 Ruby on Rails 中使用 Devise 插件进行身份验证限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11501760/

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