[ruby-on-rails] Devise-특정 사용자의 로그인을 어떻게 금지합니까?

내 응용 프로그램에서 인증을 위해 Devise를 사용하고 있습니다.

특정 사용자의 로그인을 금지하려면 어떻게해야합니까?



답변

다음과 같이하십시오.

모델에 is_active대한 열을 작성하십시오 User.

그런 다음 아래 코드를 User모델에 추가하십시오 .

class User < ActiveRecord::Base
  #this method is called by devise to check for "active" state of the model
  def active_for_authentication?
    #remember to call the super
    #then put our own check to determine "active" state using 
    #our own "is_active" column
    super and self.is_active?
  end
end

최신 정보

Matt Huggins가 언급했듯이이 메서드는 이제 호출됩니다 active_for_authentication?( Documentation ).


답변

User모델에 열 추가 : allowed_to_log_in.

그런 다음 다음을 추가하십시오 /app/models/user.rb.

def active_for_authentication?
    super and self.allowed_to_log_in?
end

사용자에게 사용자 지정 메시지를 알리려면 다음을 추가 할 수도 있습니다.

def inactive_message
    "You are not allowed to log in."
end

Devise의 표준 메시지가 다음과 같이 말하고 있기 때문에 이것이 매우 중요하다고 생각합니다.

“귀하의 계정은 아직 활성화되지 않았습니다.”

이는 사용자에게 혼란스럽고 진짜 이유는 로그인을 “금지”했기 때문입니다.


답변

인증이 아닌 인증을 원합니다. 하지만 Devise는 감성 만합니다.
Ie devise는 사용자가 자신이 말하는 사람임을 알려줍니다.
그가 사이트를 사용하는 것을 금지하려면 다른 것이 필요합니다.

승인은 인기있는 주제이며 이에 도움이 될 수있는 전체 gem 목록이 있습니다.
http://ruby-toolbox.com/categories/rails_authorization.html
선택하세요.


답변


답변