Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

sso
杨树明 5 years ago
commit e686d84866

@ -1,9 +1,18 @@
class BindUsersController < ApplicationController class BindUsersController < ApplicationController
before_action :require_login # before_action :require_login
def create def create
user = CreateBindUserService.call(current_user, create_params) # user = CreateBindUserService.call(create_params)
successful_authentication(user) if user.id != current_user.id #
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 render_ok
rescue ApplicationService::Error => ex rescue ApplicationService::Error => ex

@ -10,6 +10,14 @@ module ControllerRescueHandler
Util.logger_error e Util.logger_error e
render json: {status: -1, message: "接口数据异常"} render json: {status: -1, message: "接口数据异常"}
end end
rescue_from NoMethodError do |e|
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 ActionView::MissingTemplate, with: :object_not_found
# rescue_from ActiveRecord::RecordNotFound, with: :object_not_found # rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
rescue_from Educoder::TipException, with: :tip_show rescue_from Educoder::TipException, with: :tip_show

@ -1168,7 +1168,7 @@ class ExercisesController < ApplicationController
#班级的选择 #班级的选择
if params[:exercise_group_id].present? if params[:exercise_group_id].present?
group_id = params[:exercise_group_id] 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?) user_ids = exercise_students.pluck(:user_id).reject(&:blank?)
@exercise_users_list = @exercise_users_list.exercise_commit_users(user_ids) @exercise_users_list = @exercise_users_list.exercise_commit_users(user_ids)
end end

@ -876,10 +876,12 @@ class HomeworkCommonsController < ApplicationController
subjects = Subject.where(id: params[:subject_ids], status: 2).includes(stages: :shixuns).reorder("id desc") subjects = Subject.where(id: params[:subject_ids], status: 2).includes(stages: :shixuns).reorder("id desc")
@homework_ids = [] @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") course_module = @course.course_modules.find_by(module_type: "shixun_homework")
subjects.each do |subject| 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| 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) 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 = HomeworksService.new.create_homework shixun, @course, category, current_user
@homework_ids << homework.id @homework_ids << homework.id
CreateStudentWorkJob.perform_later(homework.id) CreateStudentWorkJob.perform_later(homework.id)

@ -30,4 +30,22 @@ class Oauth::BaseController < ActionController::Base
@_default_yun_session = "#{request.subdomain.split('.').first}_user_id" @_default_yun_session = "#{request.subdomain.split('.').first}_user_id"
# @_default_yun_session = "#{current_laboratory.try(:identifier).split('.').first}_user_id" # @_default_yun_session = "#{current_laboratory.try(:identifier).split('.').first}_user_id"
end 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 end

@ -2,7 +2,7 @@ class Oauth::WechatController < Oauth::BaseController
def create def create
user, new_user = Oauth::CreateOrFindWechatAccountService.call(current_user ,params) user, new_user = Oauth::CreateOrFindWechatAccountService.call(current_user ,params)
successful_authentication(user) successful_authentication(user) if !new_user
render_ok(new_user: new_user) render_ok(new_user: new_user)
rescue Oauth::CreateOrFindWechatAccountService::Error => ex rescue Oauth::CreateOrFindWechatAccountService::Error => ex

@ -18,18 +18,22 @@ class Oauth::CreateOrFindWechatAccountService < ApplicationService
# 存在该用户 # 存在该用户
open_user = OpenUsers::Wechat.find_by(uid: result['unionid']) 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? if user.blank? || !user.logged?
new_user = true new_user = true
# 新用户 # 新用户
login = User.generate_login('w') # login = User.generate_login('w')
# result['nickname'] = regix_emoji(result['nickname']) # result['nickname'] = regix_emoji(result['nickname'])
@user = User.new(login: login, type: 'User', status: User::STATUS_ACTIVE) # @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) # @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 end
=begin
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
if new_user if new_user
user.save! 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 # 方便后面进行账号绑定 Rails.cache.write(new_open_user.can_bind_cache_key, 1, expires_in: 1.hours) if new_user # 方便后面进行账号绑定
end end
=end
[user, new_user] [user, new_user]
rescue WechatOauth::Error => ex rescue WechatOauth::Error => ex

@ -4,17 +4,33 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0-rc.1/katex.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/contrib/auto-render.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/contrib/auto-render.min.js"></script>
<script> <script>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.getElementById('markdown_content'), { renderMathInElement(document.getElementById('markdown_content'), {
displayMode: true,
delimiters: [ delimiters: [
{left: "$$", right: "$$", display: true}, {left: "$$", right: "$$", display: true},
{left: "$", right: "$", display: false} {left: "$", right: "$", display: false}
] ]
}); });
function fix_frac_line(){
var win = window;
var frac_lines = document.getElementsByClassName("frac-line");
for (var i = 0; i < frac_lines.length; i++) {
var frac = frac_lines[i];
if (win.getComputedStyle) {
style = win.getComputedStyle(frac, '');
if (style['border-bottom-width'] == '0px') {
frac.style['border-bottom-width'] = '1px';
}
}
}
};
fix_frac_line();
}) })
</script> </script>
</head> </head>

Loading…
Cancel
Save