Я работаю над RoR-приложением с Devise. Я хочу, чтобы клиенты отправляли запрос на сервер, чтобы узнать, сколько времени осталось до тех пор, пока пользователь на клиенте не будет автоматически отключен из-за неактивности (используя модуль Timeoutable
). Я не хочу, чтобы этот запрос вызывал Devise reset обратный отсчет до тех пор, пока пользователь не выйдет из системы. Как я могу настроить это?
Это код, который у меня есть сейчас:
class SessionTimeoutController < ApplicationController
before_filter :authenticate_user!
# Calculates the number of seconds until the user is
# automatically logged out due to inactivity. Unlike most
# requests, it should not reset the timeout countdown itself.
def check_time_until_logout
@time_left = current_user.timeout_in
end
# Determines whether the user has been logged out due to
# inactivity or not. Unlike most requests, it should not reset the
# timeout countdown itself.
def has_user_timed_out
@has_timed_out = current_user.timedout? (Time.now)
end
# Resets the clock used to determine whether to log the user out
# due to inactivity.
def reset_user_clock
# Receiving an arbitrary request from a client automatically
# resets the Devise Timeoutable timer.
head :ok
end
end
SessionTimeoutController#reset_user_clock
работает, потому что каждый раз, когда RoR получает запрос от аутентифицированного пользователя, Timeoutable#timeout_in
есть reset к тому, что я настроил в Devise#timeout_in
. Как предотвратить reset в check_time_until_logout
и has_user_timed_out
?