开发者

Devise - Setting the scope when authenticating

I'm using devise for authentication. How can I set the sign-in scope? For example, say I only want to authenticate the user for the scope:

User.wh开发者_开发百科ere(:active => true)

Am I being clear? It's simple, but I can elaborate more if needed.

(I realize there is a lockable module, but my actual scope isn't for active users, it's more like current_site.users, where the current_site is based off the domain)


Just overwrite these two methods in your User model to check if the active flag is true:

# Called by Devise to see if an user can currently be signed in
def active_for_authentication?
  active? && super
end

# Called by Devise to get the proper error message when an user cannot be signed in
def inactive_message
  !active? ? :deactivated : super
end

And in your devise.en.yml, add the proper error message:

devise:
  failure:
    deactivated: "Luke, I'm your father and your account was locked!"


You could use default_scope... but that might get in your way.

Why not override devise's find_for_database_authentication method? See the wiki.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜