How to configure time out using devise?

岁酱吖の 提交于 2020-01-02 03:23:08

问题


Model:

devise :database_authenticatable, :registerable,:timeoutable, :recoverable, :rememberable, :trackable, :validatable,:timeout_in => 10.seconds

development.rb:

config.timeout_in = 10.seconds

devise.rb:

config.timeout_in = 10.seconds

回答1:


Are you expecting the page to refresh and show you a login page again? If so, that's not how the timeoutable feature works. If you're expecting it to present you with the login page when you refresh, remove the timeout part from your model and put the following in devise.rb NOT development.rb. Don't forget to restart rails server.

config.timeout_in = 1.hour

This is all documented in the devise wiki here

Also, I'm not sure about the logic behind 10 seconds?? Seems a little too short. If it's still not working, increase to (for example) five minutes and test.




回答2:


Also it's possible to set timeout_in option dynamically

class User < ActiveRecord::Base
  devise (...), :timeoutable

  def timeout_in
    if self.admin? 
      1.year
    else
      2.days
    end
  end
end


来源:https://stackoverflow.com/questions/10495390/how-to-configure-time-out-using-devise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!