From 58482e5f9ea0c824aefe9e91c59efcba0275410c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 2 Jan 2020 15:39:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 28 ++++++++++++----------- app/controllers/hacks_controller.rb | 4 ++-- app/controllers/item_banks_controller.rb | 2 +- app/views/item_banks/_item.json.jbuilder | 5 ++++ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 254d04cfd..89d53e73c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,19 +23,21 @@ class ApplicationController < ActionController::Base # 所有请求必须合法签名 def check_sign - Rails.logger.info("66666 #{params}") - suffix = request.url.split(".").last.split("?").first - suffix_arr = ["xls", "xlsx", "pdf"] # excel文件先注释 - unless suffix_arr.include?(suffix) - if params[:client_key].present? - randomcode = params[:randomcode] - # tip_exception(501, "请求不合理") unless (Time.now.to_i - randomcode.to_i).between?(0,5) - - sign = Digest::MD5.hexdigest("#{OPENKEY}#{randomcode}") - Rails.logger.info("2222 #{sign}") - tip_exception(501, "请求不合理") if sign != params[:client_key] - else - tip_exception(501, "请求不合理") + unless Rails.env.development? + Rails.logger.info("66666 #{params}") + suffix = request.url.split(".").last.split("?").first + suffix_arr = ["xls", "xlsx", "pdf"] # excel文件先注释 + unless suffix_arr.include?(suffix) + if params[:client_key].present? + randomcode = params[:randomcode] + # tip_exception(501, "请求不合理") unless (Time.now.to_i - randomcode.to_i).between?(0,5) + + sign = Digest::MD5.hexdigest("#{OPENKEY}#{randomcode}") + Rails.logger.info("2222 #{sign}") + tip_exception(501, "请求不合理") if sign != params[:client_key] + else + tip_exception(501, "请求不合理") + end end end end diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 2b4c1e847..82fdef3ae 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -61,7 +61,7 @@ class HacksController < ApplicationController hack_codes = hack.hack_codes.new(hack_code_params) hack_codes.modify_time = Time.now hack_codes.save! - new_item_params = item_params.merge({container: hack, item_type: 'PROGRAM', difficulty: params[:difficult], user_id: current_user.id}) + new_item_params = item_params.merge({container: hack, item_type: 'PROGRAM', difficulty: params[:hack][:difficult], user_id: current_user.id}) ItemBank.create!(new_item_params) end render_ok({identifier: hack.identifier}) @@ -95,7 +95,7 @@ class HacksController < ApplicationController # 更新题库相关记录 if @hack.item_bank.present? - update_item_params = item_params.merge({difficulty: params[:difficult]}) + update_item_params = item_params.merge({difficulty: params[:hack][:difficult]}) @hack.item_bank.update!(update_item_params) end end diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb index a63710336..1e7a8c961 100644 --- a/app/controllers/item_banks_controller.rb +++ b/app/controllers/item_banks_controller.rb @@ -7,7 +7,7 @@ class ItemBanksController < ApplicationController def index items = ItemBankQuery.call(params) @items_count = items.size - @items = paginate items.includes(:item_analysis, :user) + @items = paginate items.includes(:item_analysis, :user, :container) @item_basket_ids = current_user.item_baskets.pluck(:item_bank_id) end diff --git a/app/views/item_banks/_item.json.jbuilder b/app/views/item_banks/_item.json.jbuilder index 916a7bddf..92561f550 100644 --- a/app/views/item_banks/_item.json.jbuilder +++ b/app/views/item_banks/_item.json.jbuilder @@ -3,4 +3,9 @@ json.analysis item.analysis json.choices item.item_choices do |choice| json.choice_text choice.choice_text json.is_answer choice.is_answer +end +if item.item_type == "PROGRAM" + json.program_attr do + json.(item.container, :description, :language, :difficult) + end end \ No newline at end of file