|
|
|
@@ -248,44 +248,57 @@ class ApplicationController < ActionController::Base |
|
|
|
#return if params[:controller] == "main" |
|
|
|
# Find the current user |
|
|
|
#Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}") |
|
|
|
User.current = find_current_user |
|
|
|
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) |
|
|
|
|
|
|
|
# 开放课程通过链接访问的用户 |
|
|
|
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank? |
|
|
|
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}" |
|
|
|
|
|
|
|
if Digest::MD5.hexdigest(content) == params[:chinaoocKey] |
|
|
|
user = open_class_user |
|
|
|
if user |
|
|
|
start_user_session(user) |
|
|
|
set_autologin_cookie(user) |
|
|
|
if request.headers["Authorization"].present? && request.headers["Authorization"].start_with?('Bearer') |
|
|
|
tip_exception(401, "请登录后再操作!") unless valid_doorkeeper_token? |
|
|
|
if @doorkeeper_token.present? |
|
|
|
# client方法对接,需要一直带着用户标识uid |
|
|
|
if @doorkeeper_token.resource_owner_id.blank? |
|
|
|
tip_exception(-1, "缺少用户标识!") if params[:uid].nil? |
|
|
|
User.current = User.find(params[:uid]) |
|
|
|
else |
|
|
|
User.current = User.find_by(id: @doorkeeper_token.resource_owner_id) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
User.current = find_current_user |
|
|
|
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) |
|
|
|
|
|
|
|
# 开放课程通过链接访问的用户 |
|
|
|
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank? |
|
|
|
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}" |
|
|
|
|
|
|
|
if Digest::MD5.hexdigest(content) == params[:chinaoocKey] |
|
|
|
user = open_class_user |
|
|
|
if user |
|
|
|
start_user_session(user) |
|
|
|
set_autologin_cookie(user) |
|
|
|
end |
|
|
|
User.current = user |
|
|
|
end |
|
|
|
User.current = user |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
if !User.current.logged? && Rails.env.development? |
|
|
|
user = User.find 1 |
|
|
|
User.current = user |
|
|
|
start_user_session(user) |
|
|
|
# if !User.current.logged? && Rails.env.development? |
|
|
|
# user = User.find 1 |
|
|
|
# User.current = user |
|
|
|
# start_user_session(user) |
|
|
|
# end |
|
|
|
|
|
|
|
|
|
|
|
# 测试版前端需求 |
|
|
|
# logger.info("subdomain:#{request.subdomain}") |
|
|
|
# if request.subdomain != "www" |
|
|
|
# if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 |
|
|
|
# User.current = User.find 81403 |
|
|
|
# elsif params[:debug] == 'student' |
|
|
|
# User.current = User.find 8686 |
|
|
|
# elsif params[:debug] == 'admin' |
|
|
|
# logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....." |
|
|
|
# user = User.find 36480 |
|
|
|
# User.current = user |
|
|
|
# cookies.signed[:user_id] = user.id |
|
|
|
# end |
|
|
|
# end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# 测试版前端需求 |
|
|
|
logger.info("subdomain:#{request.subdomain}") |
|
|
|
# if request.subdomain != "www" |
|
|
|
# if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 |
|
|
|
# User.current = User.find 81403 |
|
|
|
# elsif params[:debug] == 'student' |
|
|
|
# User.current = User.find 8686 |
|
|
|
# elsif params[:debug] == 'admin' |
|
|
|
# logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....." |
|
|
|
# user = User.find 36480 |
|
|
|
# User.current = user |
|
|
|
# cookies.signed[:user_id] = user.id |
|
|
|
# end |
|
|
|
# end |
|
|
|
# User.current = User.find 81403 |
|
|
|
end |
|
|
|
|
|
|
|
|