From 6b3454cf57867f19bdf1787a3b97a47336746281 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 22 Nov 2019 11:47:47 +0800 Subject: [PATCH 1/5] =?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 From 0539522cf434a6e1480694734c06784847df140e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 22 Nov 2019 14:44:33 +0800 Subject: [PATCH 2/5] =?UTF-8?q?domain=20session=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c30eb6b52..4c61fb1df 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -300,9 +300,10 @@ class ApplicationController < ActionController::Base def find_current_user uid_logger("user setup start: session[:user_id] is #{session[:user_id]}") uid_logger("0000000000000user setup start: session[:user_id] is #{session[:"#{default_yun_session}"]}") - if session[:"#{default_yun_session}"] + current_domain_session = session[:"#{default_yun_session}"] + if current_domain_session # existing session - (User.active.find(session[:user_id]) rescue nil) + (User.active.find(current_domain_session) rescue nil) elsif autologin_user = try_to_autologin autologin_user elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth? From d87111e3bd66755db6a090677de9d604353eaac0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 22 Nov 2019 14:52:38 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/laboratory_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/laboratory_helper.rb b/app/controllers/concerns/laboratory_helper.rb index 37a3675f0..8302e4c6a 100644 --- a/app/controllers/concerns/laboratory_helper.rb +++ b/app/controllers/concerns/laboratory_helper.rb @@ -26,6 +26,6 @@ module LaboratoryHelper end def default_yun_session - @_default_yun_session = "#{request.subdomain.split('.').first}_user_id" + @_default_yun_session = "#{current_laboratory.split('.').first}_user_id" end end \ No newline at end of file From 0246037cdaa2f4cde4ada3851eeefc24e6ae10e4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 22 Nov 2019 17:37:49 +0800 Subject: [PATCH 4/5] seesion --- app/controllers/concerns/laboratory_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/laboratory_helper.rb b/app/controllers/concerns/laboratory_helper.rb index 8302e4c6a..37a3675f0 100644 --- a/app/controllers/concerns/laboratory_helper.rb +++ b/app/controllers/concerns/laboratory_helper.rb @@ -26,6 +26,6 @@ module LaboratoryHelper end def default_yun_session - @_default_yun_session = "#{current_laboratory.split('.').first}_user_id" + @_default_yun_session = "#{request.subdomain.split('.').first}_user_id" end end \ No newline at end of file From 3d64b1221a83d2c1e7357c6ec60a6edd97e0d9ca Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 22 Nov 2019 20:52:19 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 +- app/controllers/application_controller.rb | 14 ++++++-------- app/controllers/concerns/login_helper.rb | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 3ad85d507..28a1b5b6e 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 # 忘记密码 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4c61fb1df..c6aca5ae5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -299,11 +299,9 @@ 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]}") - uid_logger("0000000000000user setup start: session[:user_id] is #{session[:"#{default_yun_session}"]}") - current_domain_session = session[:"#{default_yun_session}"] - if current_domain_session + if session[:user_id] # existing session - (User.active.find(current_domain_session) rescue nil) + (User.active.find(session[:user_id]) rescue nil) elsif autologin_user = try_to_autologin autologin_user elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth? @@ -315,10 +313,10 @@ class ApplicationController < ActionController::Base def try_to_autologin if cookies[autologin_cookie_name] # auto-login feature starts a new session - 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 = User.try_to_autologin(cookies[autologin_cookie_name]) + if user + start_user_session(user) + end user end end diff --git a/app/controllers/concerns/login_helper.rb b/app/controllers/concerns/login_helper.rb index 605d0faf4..8497799e3 100644 --- a/app/controllers/concerns/login_helper.rb +++ b/app/controllers/concerns/login_helper.rb @@ -73,8 +73,8 @@ module LoginHelper # # session[:"#{request.subdomain}_user_id"] = user.id # # end - # session[:user_id] = user.id - session[:"#{default_yun_session}"] = 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