From cc3fc72cf9d70e3e3f2ed54c93040654a88bd000 Mon Sep 17 00:00:00 2001 From: Janis4411 Date: Tue, 2 Aug 2022 13:46:39 +0200 Subject: [PATCH] slight changes to application controller to be more readable --- app/controllers/application_controller.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bb42b239..173f1e25 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,7 +15,11 @@ class ApplicationController < ActionController::Base rescue_from ActionController::InvalidAuthenticityToken, with: :render_csrf_error def current_user - @current_user ||= ExternalUser.find_by(id: session[:external_user_id]) || login_from_session || login_from_other_sources || nil + @current_user ||= ExternalUser.find_by(id: session[:external_user_id]) || + login_from_session || + login_from_other_sources || + login_from_authentication_token || + nil end def require_user! @@ -32,6 +36,13 @@ class ApplicationController < ActionController::Base end end + def login_from_authentication_token + token = AuthenticationToken.find_by(shared_secret: params[:token]) + return unless token + + auto_login(token.user) if token.expire_at.future? + end + def set_sentry_context return if current_user.blank?