开发者

additional logic in devise authentication

开发者 https://www.devze.com 2023-03-01 04:27 出处:网络
please how and where can i place additional authentication logic in devise? i have added a custom column called expire_date in my users table and it is a date column.

please how and where can i place additional authentication logic in devise?

i have added a custom column called expire_date in my users table and it is a date column.

i want开发者_如何学运维 an additional requirement that the date there must not be later than todays date before allowing them to be authenticated.

please where can i add this logic?

thanks


Or you can override the active_for_authentication? method in your User model

def active_for_authentication?
 super && (test your dates here)
end

If it is inactive, it will generate a flash message about the account not being active. If you want something different like "This user is not active yet", change the setting for :inactive in the file config/locales/devise.en.yml. This is taken mostly from the Devise wiki.


Create your own controller that inherits from Devise::SessionsController

app / controllers / users /sessions_controller.rb

class Users::SessionsController < Devise::SessionsController
...
Overwrite the new method
...
Change what else you need to change
...
end

Add a new route to the routes file, and you are good to go.

0

精彩评论

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