2

active_for_authentication을 사용하고 있습니까? 활성 사용자 만이 장치를 통해 로그인 할 수 있습니다. 하지만 작동하지 않습니다.active_for_authentication? 작동하지 않음

내 컨트롤러 :

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" 

Y를 deactivated_ind 사용하여/N 나 사용자가 비활성/활성화 확인. 이제는 사용자가 deactivated_ind colomn에 N이있는 사용자 만 로그인 할 수있게하려고합니다.

답변

2

문제의 일부분은 부울 대신 "deactivated_ind"문자열을 사용하고있는 것 같습니다. 둘 다 "n"이 아니므로 "N"문자열과 "Y"문자열을 부울 값으로 사용할 때 모두 true입니다.

2
  1. active_for_authentication? 요구하지

  2. 컨트롤러에, 모델의 방법이 될 (귀하의 경우 문제가되지 않습니다,하지만 내이었다) active_for_authentication?가에 공공 방법이어야합니다 모델

+1

나는 보통 'private'라고 쓰지만,'active_for_authentication' (그리고 그것의 동반자'inactive_message' meth)과 같은 모든 Devise 콜백 메소드를 덮어 씁니다. od)는 '공개'인 것처럼 보입니다. –