Obviously User.first.current_sign_in_at is what I want to use, but how to add this in a hook?
before_save :login_hook, :if => current_sign_in_at_changed?
but I get method doesn't exist.
Here it seems to work:
Execute JS code on user sign up/sign in with Rails + Devise
I have devise :trackable in the model and t.trackable in my migration. The database value is also updated
For now, forget the hook, just try using
if (Time.new - current_user.last_sign_in_at) < 600 # seconds, so 10 minutes
do stuff
else
# do other stuff, probably a redirect
# possibly sign_out_and_redirect(resource_name)
end
You probably want this in your application_controller so as to apply to all.
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.