From ba6df7b9b1d8667da30586ea46d469a2a49adc56 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 29 May 2019 22:00:44 +0800 Subject: [PATCH] 1 --- app/controllers/application_controller.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9018cc6c..e6240714 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -193,6 +193,21 @@ class ApplicationController < ActionController::Base find_current_user end + def set_autologin_cookie(user) + token = Token.get_or_create_permanent_login_token(user) + cookie_options = { + :value => token.value, + :expires => 1.month.from_now, + :path => (Redmine::Configuration['autologin_cookie_path'] || '/'), + :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false), + :httponly => true + } + if Redmine::Configuration['cookie_domain'].present? + cookie_options = cookie_options.merge(domain: Redmine::Configuration['cookie_domain']) + end + cookies[autologin_cookie_name] = cookie_options + end + def find_current_user user = nil unless api_request? @@ -209,6 +224,7 @@ class ApplicationController < ActionController::Base user = uw.user if uw elsif params[:authToken] user = Token.find_by_value(params[:authToken]).user + set_autologin_cookie(user) session[:user_id] = user.id end end