From 4ee0b2a8656ac385b54b24d1fb9910f502af14e6 Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Fri, 26 Apr 2019 18:11:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=9B=B8=E5=85=B3=E9=A1=B5=E9=9D=A2=E5=87=BA?= =?UTF-8?q?=E7=8E=B0500=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 5 +++++ app/controllers/challenges_controller.rb | 2 ++ app/controllers/shixuns_controller.rb | 2 +- app/controllers/subjects_controller.rb | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 22888abb..4bdcff56 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1141,4 +1141,9 @@ class ApplicationController < ActionController::Base redirect_to authorize_url end + + def user_login_and_from_openi + url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer + URI(url).host == 'openi.org.cn' && !current_user.logged? + end end diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 5bd8f537..59102172 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -1,6 +1,8 @@ # encoding: utf-8 class ChallengesController < ApplicationController layout "base_shixun" + # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 + before_filter :handle_openi_request, if: -> { user_login_and_from_openi } before_filter :check_authentication, :except => [:index] before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose] diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0572f8fa..5cadc9a4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -3,7 +3,7 @@ class ShixunsController < ApplicationController layout 'base_shixun' # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 - before_filter :handle_openi_request, if: -> {URI(request.referer).host == 'openi.org.cn' && !current_user.logged?} + before_filter :handle_openi_request, if: -> { user_login_and_from_openi } before_filter :require_login, :except => [:ghook, :download_file, :show, :index] before_filter :check_authentication, :except => [:ghook, :download_file, :show, :index] before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses, :new_disscuss, :shixun_migrate, :qrcode, :download_file, :departments, :get_mirror_script, :send_message_to_administrator] diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 2db71ee7..14d738c4 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -2,7 +2,7 @@ class SubjectsController < ApplicationController layout 'base_subject' # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 - before_filter :handle_openi_request, if: -> {URI(request.referer).host == 'openi.org.cn' && !current_user.logged?} + before_filter :handle_openi_request, if: -> { user_login_and_from_openi } before_filter :require_login, :except => [:show, :index] before_filter :check_authentication, :except => [:show, :index] before_filter :find_subject, :except => [:index, :new, :create, :create_subject, :new_subject, :append_to_stage, :send_to_course]