From 41cec586aad1dc3dac8668213a1066be90a837f6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Feb 2020 20:06:39 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=9A=84=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E7=BB=91=E5=AE=9A=E6=B5=81=E7=A8=8B=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bind_users_controller.rb | 15 ++++++++++++--- app/controllers/oauth/base_controller.rb | 18 ++++++++++++++++++ app/controllers/oauth/wechat_controller.rb | 2 +- .../create_or_find_wechat_account_service.rb | 17 +++++++++++------ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/controllers/bind_users_controller.rb b/app/controllers/bind_users_controller.rb index 354b2993b..8fe5f54a7 100644 --- a/app/controllers/bind_users_controller.rb +++ b/app/controllers/bind_users_controller.rb @@ -1,9 +1,18 @@ class BindUsersController < ApplicationController - before_action :require_login + # before_action :require_login def create - user = CreateBindUserService.call(current_user, create_params) - successful_authentication(user) if user.id != current_user.id + # user = CreateBindUserService.call(create_params) + # + + raise Error, '系统错误' if session_unionid.blank? + + bind_user = User.try_to_login(params[:username], params[:password]) + raise Error, '用户名或者密码错误' if bind_user.blank? + raise Error, '该账号已被绑定,请更换其他账号进行绑定' if bind_user.bind_open_user?(params[:type].to_s) + + OpenUsers::Wechat.create!(user: bind_user, uid: session_unionid) + successful_authentication(bind_user) render_ok rescue ApplicationService::Error => ex diff --git a/app/controllers/oauth/base_controller.rb b/app/controllers/oauth/base_controller.rb index 11ac69d71..930abead5 100644 --- a/app/controllers/oauth/base_controller.rb +++ b/app/controllers/oauth/base_controller.rb @@ -30,4 +30,22 @@ class Oauth::BaseController < ActionController::Base @_default_yun_session = "#{request.subdomain.split('.').first}_user_id" # @_default_yun_session = "#{current_laboratory.try(:identifier).split('.').first}_user_id" end + + def session_openid + session[:openid] + end + + def set_session_openid(openid) + Rails.logger.info("[wechat] set session openid: #{openid}") + session[:openid] = openid + end + + def session_unionid + session[:unionid] + end + + def set_session_unionid(unionid) + Rails.logger.info("[wechat] set session unionid: #{unionid}") + session[:unionid] = unionid + end end \ No newline at end of file diff --git a/app/controllers/oauth/wechat_controller.rb b/app/controllers/oauth/wechat_controller.rb index 6c0c53eb6..f95116535 100644 --- a/app/controllers/oauth/wechat_controller.rb +++ b/app/controllers/oauth/wechat_controller.rb @@ -2,7 +2,7 @@ class Oauth::WechatController < Oauth::BaseController def create user, new_user = Oauth::CreateOrFindWechatAccountService.call(current_user ,params) - successful_authentication(user) + successful_authentication(user) if !new_user render_ok(new_user: new_user) rescue Oauth::CreateOrFindWechatAccountService::Error => ex diff --git a/app/services/oauth/create_or_find_wechat_account_service.rb b/app/services/oauth/create_or_find_wechat_account_service.rb index 75091a5c3..8eb44108b 100644 --- a/app/services/oauth/create_or_find_wechat_account_service.rb +++ b/app/services/oauth/create_or_find_wechat_account_service.rb @@ -18,18 +18,22 @@ class Oauth::CreateOrFindWechatAccountService < ApplicationService # 存在该用户 open_user = OpenUsers::Wechat.find_by(uid: result['unionid']) - return [open_user.user, new_user] if open_user.present? + return [open_user.user, new_user] if open_user.present? && open_user.user.present? if user.blank? || !user.logged? new_user = true # 新用户 - login = User.generate_login('w') - # result['nickname'] = regix_emoji(result['nickname']) - @user = User.new(login: login, type: 'User', status: User::STATUS_ACTIVE) - #@user = User.new(login: login, nickname: result['nickname'], type: 'User', status: User::STATUS_ACTIVE) - + # login = User.generate_login('w') + # result['nickname'] = regix_emoji(result['nickname']) + # @user = User.new(login: login, type: 'User', status: User::STATUS_ACTIVE) + # @user = User.new(login: login, nickname: result['nickname'], type: 'User', status: User::STATUS_ACTIVE) + set_session_openid(result['openid']) + set_session_unionid(result['unionid']) + else + OpenUsers::Wechat.create!(user: user, uid: result['unionid']) end +=begin ActiveRecord::Base.transaction do if new_user user.save! @@ -46,6 +50,7 @@ class Oauth::CreateOrFindWechatAccountService < ApplicationService Rails.cache.write(new_open_user.can_bind_cache_key, 1, expires_in: 1.hours) if new_user # 方便后面进行账号绑定 end +=end [user, new_user] rescue WechatOauth::Error => ex From 582307e0360ceced05b0ee725d91d5da66ef1312 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Feb 2020 22:33:57 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E9=80=89=E7=94=A8?= =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B=E6=97=B6=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=9D=83=E9=99=90=E7=9A=84=E5=88=A4=E6=96=AD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ac3b84871..22e7636c4 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -876,10 +876,12 @@ class HomeworkCommonsController < ApplicationController subjects = Subject.where(id: params[:subject_ids], status: 2).includes(stages: :shixuns).reorder("id desc") @homework_ids = [] - none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + # none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) course_module = @course.course_modules.find_by(module_type: "shixun_homework") subjects.each do |subject| + shixun_ids = subject.shixuns.where(use_scope: 0).pluck(:id) + + subject.shixuns.joins(:shixun_schools).where("school_id = #{current_user.try(:school_id).to_i} and use_scope = 1").pluck(:id) subject.stages.each do |stage| @@ -889,7 +891,7 @@ class HomeworkCommonsController < ApplicationController course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) # 去掉不对当前用户的单位公开的实训,已发布的实训 - stage.shixuns.no_jupyter.where.not(shixuns: {id: none_shixun_ids}).unhidden.each do |shixun| + stage.shixuns.no_jupyter.where(id: shixun_ids).unhidden.each do |shixun| homework = HomeworksService.new.create_homework shixun, @course, category, current_user @homework_ids << homework.id CreateStudentWorkJob.perform_later(homework.id) From bb5e8ee0b0df678a5c3d359e403ea099de801d23 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Feb 2020 10:04:52 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=88=86=E7=8F=AD=E7=AD=9B=E9=80=89=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/controller_rescue_handler.rb | 4 ++++ app/controllers/exercises_controller.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/controller_rescue_handler.rb b/app/controllers/concerns/controller_rescue_handler.rb index 60ac09d64..a3e603bd9 100644 --- a/app/controllers/concerns/controller_rescue_handler.rb +++ b/app/controllers/concerns/controller_rescue_handler.rb @@ -10,6 +10,10 @@ module ControllerRescueHandler Util.logger_error e render json: {status: -1, message: "接口数据异常"} end + rescue_from NoMethodError do |e| + Util.logger_error e + render json: {status: -1, message: "接口方法异常"} + end # rescue_from ActionView::MissingTemplate, with: :object_not_found # rescue_from ActiveRecord::RecordNotFound, with: :object_not_found rescue_from Educoder::TipException, with: :tip_show diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 60a437fdc..15f5c67d9 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1168,7 +1168,7 @@ class ExercisesController < ApplicationController #班级的选择 if params[:exercise_group_id].present? group_id = params[:exercise_group_id] - exercise_students = @course_all_members.course_find("course_group_id", group_id) #试卷所分班的全部人数 + exercise_students = @course_all_members.course_find_by_ids("course_group_id", group_id) #试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?) @exercise_users_list = @exercise_users_list.exercise_commit_users(user_ids) end From 84d0218e482847b35f2fb0780df194c1085bc977 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Feb 2020 10:09:29 +0800 Subject: [PATCH 4/7] 1 --- db/migrate/20200218060227_create_salesmans.rb | 14 +++++++------- .../20200218060757_create_salesman_channels.rb | 10 +++++----- .../20200218060807_create_salesman_customers.rb | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/db/migrate/20200218060227_create_salesmans.rb b/db/migrate/20200218060227_create_salesmans.rb index 74c78da07..8b9e6f367 100644 --- a/db/migrate/20200218060227_create_salesmans.rb +++ b/db/migrate/20200218060227_create_salesmans.rb @@ -1,11 +1,11 @@ class CreateSalesmans < ActiveRecord::Migration[5.2] def change - create_table :salesmans do |t| - t.references :user - t.string :name - t.integer :salesman_channels_count - t.integer :salesman_customers_count - t.timestamps - end + # create_table :salesmans do |t| + # t.references :user + # t.string :name + # t.integer :salesman_channels_count + # t.integer :salesman_customers_count + # t.timestamps + # end end end diff --git a/db/migrate/20200218060757_create_salesman_channels.rb b/db/migrate/20200218060757_create_salesman_channels.rb index e43fd0a51..48946aba2 100644 --- a/db/migrate/20200218060757_create_salesman_channels.rb +++ b/db/migrate/20200218060757_create_salesman_channels.rb @@ -1,9 +1,9 @@ class CreateSalesmanChannels < ActiveRecord::Migration[5.2] def change - create_table :salesman_channels do |t| - t.references :salesman - t.references :school - t.timestamps - end + # create_table :salesman_channels do |t| + # t.references :salesman + # t.references :school + # t.timestamps + # end end end diff --git a/db/migrate/20200218060807_create_salesman_customers.rb b/db/migrate/20200218060807_create_salesman_customers.rb index a27f8ca95..7b9c99753 100644 --- a/db/migrate/20200218060807_create_salesman_customers.rb +++ b/db/migrate/20200218060807_create_salesman_customers.rb @@ -1,10 +1,10 @@ class CreateSalesmanCustomers < ActiveRecord::Migration[5.2] def change - create_table :salesman_customers do |t| - t.references :salesman - t.references :user - t.references :school - t.timestamps - end + # create_table :salesman_customers do |t| + # t.references :salesman + # t.references :user + # t.references :school + # t.timestamps + # end end end From b8fc11828c139269848f2388ac248a15793897e5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Feb 2020 10:10:15 +0800 Subject: [PATCH 5/7] 1 --- db/migrate/20200218060227_create_salesmans.rb | 14 +++++++------- .../20200218060757_create_salesman_channels.rb | 10 +++++----- .../20200218060807_create_salesman_customers.rb | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/db/migrate/20200218060227_create_salesmans.rb b/db/migrate/20200218060227_create_salesmans.rb index 8b9e6f367..74c78da07 100644 --- a/db/migrate/20200218060227_create_salesmans.rb +++ b/db/migrate/20200218060227_create_salesmans.rb @@ -1,11 +1,11 @@ class CreateSalesmans < ActiveRecord::Migration[5.2] def change - # create_table :salesmans do |t| - # t.references :user - # t.string :name - # t.integer :salesman_channels_count - # t.integer :salesman_customers_count - # t.timestamps - # end + create_table :salesmans do |t| + t.references :user + t.string :name + t.integer :salesman_channels_count + t.integer :salesman_customers_count + t.timestamps + end end end diff --git a/db/migrate/20200218060757_create_salesman_channels.rb b/db/migrate/20200218060757_create_salesman_channels.rb index 48946aba2..e43fd0a51 100644 --- a/db/migrate/20200218060757_create_salesman_channels.rb +++ b/db/migrate/20200218060757_create_salesman_channels.rb @@ -1,9 +1,9 @@ class CreateSalesmanChannels < ActiveRecord::Migration[5.2] def change - # create_table :salesman_channels do |t| - # t.references :salesman - # t.references :school - # t.timestamps - # end + create_table :salesman_channels do |t| + t.references :salesman + t.references :school + t.timestamps + end end end diff --git a/db/migrate/20200218060807_create_salesman_customers.rb b/db/migrate/20200218060807_create_salesman_customers.rb index 7b9c99753..a27f8ca95 100644 --- a/db/migrate/20200218060807_create_salesman_customers.rb +++ b/db/migrate/20200218060807_create_salesman_customers.rb @@ -1,10 +1,10 @@ class CreateSalesmanCustomers < ActiveRecord::Migration[5.2] def change - # create_table :salesman_customers do |t| - # t.references :salesman - # t.references :user - # t.references :school - # t.timestamps - # end + create_table :salesman_customers do |t| + t.references :salesman + t.references :user + t.references :school + t.timestamps + end end end From c113e527900d50bde80cf482908477b324cca5d4 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Fri, 21 Feb 2020 11:22:04 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpdf=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84=E5=85=AC=E5=BC=8F=E6=A8=AA=E7=BA=BF=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_export/blank_exercise.html.erb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index ae92605dc..936cb6408 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -4,17 +4,33 @@ - + From 80559d41094623d1a34109d09adb261ffe52c596 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Feb 2020 16:05:11 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/controller_rescue_handler.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/concerns/controller_rescue_handler.rb b/app/controllers/concerns/controller_rescue_handler.rb index a3e603bd9..6ff15cfbc 100644 --- a/app/controllers/concerns/controller_rescue_handler.rb +++ b/app/controllers/concerns/controller_rescue_handler.rb @@ -14,6 +14,10 @@ module ControllerRescueHandler Util.logger_error e render json: {status: -1, message: "接口方法异常"} end + + rescue_from ActionController::UnknownFormat do |e| + render json: {status: -1, message: "接口调用非JSON格式"} + end # rescue_from ActionView::MissingTemplate, with: :object_not_found # rescue_from ActiveRecord::RecordNotFound, with: :object_not_found rescue_from Educoder::TipException, with: :tip_show