From 93f5c213e0054ce555fd7ec21b6c90ee42d020d7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 20 Nov 2019 19:15:53 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=88=91=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/hack_user_lastest_code.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb index 1d3e20f87..28cc62db4 100644 --- a/app/models/hack_user_lastest_code.rb +++ b/app/models/hack_user_lastest_code.rb @@ -8,7 +8,7 @@ class HackUserLastestCode < ApplicationRecord belongs_to :user has_many :hack_user_codes, dependent: :destroy has_one :hack_user_debug - scope :mine, ->(author_id){ find_by(user_id: author_id) } + scope :mine, ->(author_id){ where(user_id: author_id) } scope :passed, -> {where(status: 1)} end From f149129f921e165a2f2ebf71f597b791a60d9b1e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 20 Nov 2019 19:21:06 +0800 Subject: [PATCH 2/5] 1 --- config/routes.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index abe31340d..81c419a7e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,7 +44,9 @@ Rails.application.routes.draw do get :start get :result end - resources :comments + resources :comments do + + end end resources :hack_user_lastest_codes, path: :myproblems, param: :identifier do From 7e50b42b9e55bb705ae506ea8041bf02a15966bf Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 20 Nov 2019 19:31:26 +0800 Subject: [PATCH 3/5] fixbug --- app/controllers/hacks_controller.rb | 2 +- app/models/hack_user_lastest_code.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 213c38c7f..915e58882 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -27,7 +27,7 @@ class HacksController < ApplicationController # 筛选过滤与排序 params_filter_or_order # 我解决的编程题数 - user_codes = HackUserLastestCode.joins(:hack).mine(current_user).passed + user_codes = HackUserLastestCode.joins(:hack).mine_hack(current_user).passed @simple_count = user_codes.where(hacks: {difficult: 1}).count @medium_count = user_codes.where(hacks: {difficult: 2}).count @diff_count = user_codes.where(hacks: {difficult: 3}).count diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb index 28cc62db4..b4a707603 100644 --- a/app/models/hack_user_lastest_code.rb +++ b/app/models/hack_user_lastest_code.rb @@ -8,7 +8,8 @@ class HackUserLastestCode < ApplicationRecord belongs_to :user has_many :hack_user_codes, dependent: :destroy has_one :hack_user_debug - scope :mine, ->(author_id){ where(user_id: author_id) } + scope :mine, ->(author_id){ find_by(user_id: author_id) } + scope :mine_hack, ->(author_id){ where(user_id: author_id) } scope :passed, -> {where(status: 1)} end From 63bc151b39abcf7f74505bf259dde1272d848a48 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 20 Nov 2019 19:50:18 +0800 Subject: [PATCH 4/5] reset --- app/controllers/application_controller.rb | 10 +++------ app/controllers/concerns/login_helper.rb | 25 ++++++++++------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index adef28e03..1bc2bad7d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -291,14 +291,10 @@ class ApplicationController < ActionController::Base # Returns the current user or nil if no user is logged in # and starts a session if needed def find_current_user - re_subdomain = "#{request.subdomain.split('.').first}_user_id" - - Rails.logger.info("find current_user: subdomain is #{re_subdomain} and user session is #{session[:user_id]} -- #{session[:"#{re_subdomain}"]}") - Rails.logger.info("-----------------------------") - Rails.logger.info("domain session is: #{session[:"#{request.subdomain.split('.').first}_user_id"]}") - if session[:"#{re_subdomain}"] + uid_logger("user setup start: session[:user_id] is #{session[:user_id]}") + if session[:user_id] # existing session - (User.active.find(session[:"#{re_subdomain}"]) 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? diff --git a/app/controllers/concerns/login_helper.rb b/app/controllers/concerns/login_helper.rb index 0126eb6b0..b3ec6da63 100644 --- a/app/controllers/concerns/login_helper.rb +++ b/app/controllers/concerns/login_helper.rb @@ -62,21 +62,18 @@ module LoginHelper end def start_user_session(user) - re_subdomain = "#{request.subdomain.split('.').first}_user_id" + # re_subdomain = "#{request.subdomain.split('.').first}_user_id" + # session[:"#{request.subdomain}_user_id"] = user.id + # Rails.logger.info("domain_user_id session is: 3333332222111#{session[:"#{request.subdomain}_user_id"]}") + # Rails.logger.info("user_id session is: 3333332222111#{session[:"#{request.subdomain}_user_id"]}") + # + # # if current_laboratory.main_site? + # # session[:user_id] = user.id + # # else + # # session[:"#{request.subdomain}_user_id"] = user.id + # # end - session[:"#{re_subdomain}"] = nil - session[:user_id] = nil - # session[:"#{re_subdomain}"] = user.id - Rails.logger.info("domain_user_id session is: 3333332222111#{session[:"#{re_subdomain}"]}") - Rails.logger.info("user_id session is: 3333332222111#{session[:user_id]}") - - # if current_laboratory.main_site? - # session[:user_id] = user.id - # else - # session[:"#{request.subdomain}_user_id"] = user.id - # end - - # session[:user_id] = user.id + session[:user_id] = user.id session[:ctime] = Time.now.utc.to_i session[:atime] = Time.now.utc.to_i end From 3bc94842c32a8957e93f6b2a12d2bb8a6a2c3efb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 20 Nov 2019 20:21:44 +0800 Subject: [PATCH 5/5] 1 --- app/controllers/hack_user_lastest_codes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb index 56cda57d7..fcbecec0d 100644 --- a/app/controllers/hack_user_lastest_codes_controller.rb +++ b/app/controllers/hack_user_lastest_codes_controller.rb @@ -103,7 +103,7 @@ class HackUserLastestCodesController < ApplicationController if exec_mode == "submit" @hack.hack_sets.map{|set| {input: set.input, output: set.output, caseId: set.id}} else - {input: params[:input]} + [{input: params[:input]}] end testCases = Base64.urlsafe_encode64(test_sets.to_json) #codeFileContent = Base64.urlsafe_encode64(@my_hack.code)