]> cat aescling's git repositories - mastodon.git/commitdiff
Update session activation time (fixes #5605) (#7408)
authorThibG <thib@sitedethib.com>
Fri, 11 May 2018 11:20:58 +0000 (13:20 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 11 May 2018 11:20:58 +0000 (13:20 +0200)
app/controllers/application_controller.rb
app/controllers/concerns/session_tracking_concern.rb [new file with mode: 0644]

index 5885264470804d605667bc0f59021662ac867df4..5b22f17c63e666430ae3e8dc10754b518e19e18f 100644 (file)
@@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base
 
   include Localized
   include UserTrackingConcern
+  include SessionTrackingConcern
 
   helper_method :current_account
   helper_method :current_session
diff --git a/app/controllers/concerns/session_tracking_concern.rb b/app/controllers/concerns/session_tracking_concern.rb
new file mode 100644 (file)
index 0000000..45361b0
--- /dev/null
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module SessionTrackingConcern
+  extend ActiveSupport::Concern
+
+  UPDATE_SIGN_IN_HOURS = 24
+
+  included do
+    before_action :set_session_activity
+  end
+
+  private
+
+  def set_session_activity
+    return unless session_needs_update?
+    current_session.touch
+  end
+
+  def session_needs_update?
+    !current_session.nil? && current_session.updated_at < UPDATE_SIGN_IN_HOURS.hours.ago
+  end
+end