From 6b3454cf57867f19bdf1787a3b97a47336746281 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 22 Nov 2019 11:47:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 4 ++-- app/controllers/application_controller.rb | 11 ++++++----- app/controllers/concerns/laboratory_helper.rb | 5 +++++ app/controllers/concerns/login_helper.rb | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 2d1b39590..3ad85d507 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -94,7 +94,7 @@ class AccountsController < ApplicationController successful_authentication(@user) login_control.clear # 重置每日密码错误次数 - session[:user_id] = @user.id + # session[:user_id] = @user.id end # 忘记密码 @@ -127,7 +127,7 @@ class AccountsController < ApplicationController end end - def successful_authentication(user) + def successful_authentication(user) uid_logger("Successful authentication start: '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}") # Valid user self.logged_user = user diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f04d126f4..978f0c6ce 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -299,7 +299,8 @@ class ApplicationController < ActionController::Base # and starts a session if needed def find_current_user uid_logger("user setup start: session[:user_id] is #{session[:user_id]}") - if session[:user_id] + uid_logger("0000000000000user setup start: session[:user_id] is #{session[:"#{default_yun_session}"]}") + if session[:"#{default_yun_session}"] # existing session (User.active.find(session[:user_id]) rescue nil) elsif autologin_user = try_to_autologin @@ -313,10 +314,10 @@ class ApplicationController < ActionController::Base def try_to_autologin if cookies[autologin_cookie_name] # auto-login feature starts a new session - user = User.try_to_autologin(cookies[autologin_cookie_name]) - if user - start_user_session(user) - end + user = nil + Rails.logger.info("111111111111111111#{default_yun_session}, session is #{session[:"#{default_yun_session}"]} ") + user = User.try_to_autologin(cookies[autologin_cookie_name]) if session[:"#{default_yun_session}"] + start_user_session(user) if user user end end diff --git a/app/controllers/concerns/laboratory_helper.rb b/app/controllers/concerns/laboratory_helper.rb index 870a1d90e..37a3675f0 100644 --- a/app/controllers/concerns/laboratory_helper.rb +++ b/app/controllers/concerns/laboratory_helper.rb @@ -6,6 +6,7 @@ module LaboratoryHelper helper_method :current_laboratory helper_method :default_setting + helper_method :default_yun_session end def current_laboratory @@ -23,4 +24,8 @@ module LaboratoryHelper def setup_laboratory Laboratory.current = current_laboratory end + + def default_yun_session + @_default_yun_session = "#{request.subdomain.split('.').first}_user_id" + end end \ No newline at end of file diff --git a/app/controllers/concerns/login_helper.rb b/app/controllers/concerns/login_helper.rb index b3ec6da63..605d0faf4 100644 --- a/app/controllers/concerns/login_helper.rb +++ b/app/controllers/concerns/login_helper.rb @@ -73,7 +73,8 @@ module LoginHelper # # session[:"#{request.subdomain}_user_id"] = user.id # # end - session[:user_id] = user.id + # session[:user_id] = user.id + session[:"#{default_yun_session}"] = user.id session[:ctime] = Time.now.utc.to_i session[:atime] = Time.now.utc.to_i end