1

Rails Deviseプラグインの経験はありますか?私のプロジェクトのCozでは、ユーザーがユーザー名とパスワードを入力したときに、ユーザーがアクティブかどうかを別のテーブルで確認する必要があります。2つのテーブルがあります。最初のテーブルはとでuser、もう1つrole_membershiprole_membershipテーブルには。という名前の列がありますactive_statusactive_status = 1そうしないと、ユーザーがシステムにログインできないかどうかを確認する必要があります。ここの誰もが、別のテーブルの値をチェックするようにDeviseプラグインを構成する方法を知っています。いくつかのチュートリアルを見つけましたが、すべて同じテーブルのフィールドにチェックインすることについて言及しています。

ありがとう

4

2 に答える 2

4

ユーザーモデルを変更して、2つの追加メソッドを含めます

  • active_for_authentication?
  • activate_message

http://pivotallabs.com/users/carl/blog/articles/1619-standup-3-21-2011-deactivating-users-in-deviseを参照してください(注:これは古いバージョンの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/

于 2012-07-16T14:54:20.907 に答える
0

私の最善のアイデアは、devise session#createメソッドをオーバーライドすることです。それを行うために:

#app/controllers/sessions_controller.rb

class SessionsController < Devise::SessionsController

  def create
    resource = warden.authenticate!(auth_options)
    #resource.is_active? should be implemented by you
    if resource.is_active?
      set_flash_message(:notice, :signed_in) if is_navigational_format?
      sign_in(resource_name, resource)
      respond_with resource, :location => after_sign_in_path_for(resource)
    else
      #put here your inactive user response
    end
  end

end

およびroutes.rb内

devise_for :users, :controllers => {:sessions => "sessions" }
于 2012-07-16T09:51:26.833 に答える