Module: Devise::Automaticlogout::Controllers::ClassMethods

Defined in:
lib/devise/automaticlogout/controllers.rb

Instance Method Summary collapse

Instance Method Details

#devise_automatic_logout(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/devise/automaticlogout/controllers.rb', line 9

def devise_automatic_logout(options = {})
  prepend_before_action do |c|
    time = options.fetch(:time, nil)
    message = options.fetch(:message, DEFAULT_MESSAGE)
    scope = options.fetch(:scope, 'user')

    seconds = if time&.positive?
                time
              else
                mapping = Devise.mappings[scope.to_sym]
                return unless mapping

                mapping.to.timeout_in.seconds.to_i
              end

    if seconds
      c.session[:devise_autl_message] = message
      c.session[:devise_autl_seconds] = seconds
    end
  end
end