gpt4 book ai didi

ruby-on-rails - active_for_authentication?不工作

转载 作者:行者123 更新时间:2023-12-04 06:21:02 25 4
gpt4 key购买 nike

我正在使用 active_for_authentication?只允许活跃用户通过设计登录。但它不起作用。

我的 Controller :

class DashboardUsersController < ApplicationController
def active_for_authentication?
super && self.deactivated_ind
end

def inactive_message
"Sorry, this account has been deactivated."
end

我的模型:

class DashboardUser < ActiveRecord::Base

devise :database_authenticatable,:rememberable, :trackable, :validatable, :timeoutable

attr_accessor :login

def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["username = :value OR lower(email) = lower(:value)", { :value => login }]).first
else
where(conditions).first
end
end
end

我的用户表:

t.string   "deactivated_ind",      limit: 1
t.date "deactivated_date"

通过使用 deactivated_ind Y/N i 检查用户是否活跃。现在我想让设计只登录那些在 deactivated_ind colomn 中有 N 的用户

最佳答案

  1. active_for_authentication? 需要是模型 上的方法,而不是 Controller 上的方法

  2. (在你的情况下不是问题,但在我的情况下)active_for_authentication? 必须是模型上的public 方法

关于ruby-on-rails - active_for_authentication?不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26859346/

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