I use devise to deal with Session.
I need to check if a user is validate by admin before sign in.
I added a boolean field in my model 'is_validated'.
How can I check this field before sign_in a user ?
You need to overwrite the active_for_authentication?
function of devise. Basically you place your extra condition in that method and only if that method is true one can log in.
You can find more details here: https://github.com/plataformatec/devise/wiki/How-To:-Customize-user-account-status-validation-when-logging-in
Overwrite the active_for_authentication? method in your model
Like this .......
class Your_model
def active_for_authentication?
super && is_validated?
end
end
This returns true if user is validated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.