我正在构建一个rails应用程序,如果当前时间超过6PM,我必须自动注销少数用户,如果当前时间超过晚上7点,则必须自动注销其他用户。我正在使用设计进行身份验证。我没有找到任何使用设计的解决方案。设计只有一个timeout_in参数用于不活动。
我也尝试过delayed_job。但在异步任务执行期间,无法识别会话哈希。
我缺少某种明显的解决方案吗?
答案 0 :(得分:1)
您可以在版本1.5.2的Devise上动态设置有效期。 https://github.com/plataformatec/devise/wiki/How-To%3a-Add-timeout_in-value-dynamically
也许你可以尝试这样的事情:
class User < ActiveRecord::Base
devise (...), :timeoutable
def timeout_in
if should_logout_at_19
timeout_period_for 19
elsif should_logout_at_18
timeout_period_for 18
else
...
end
end
# period in seconds until next session expiration hour.
def timeout_period_for(given_hour)
next_time = if Time.now.hour > given_hour
Date.tomorrow.to_time.change(hour: given_hour)
else
Date.today.to_time.change(hour: given_hour)
end
next_time - Time.now
end
def should_logout_at_19
# user criteria to logout at 7 PM
end
end