From 2c980c14f5c59bcb9313b0f3406118a6e5073a9c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 29 May 2019 21:54:33 +0800 Subject: [PATCH] 1 --- app/api/mobile/api.rb | 12 ++++++------ app/api/mobile/apis/cnmooc.rb | 4 ---- app/controllers/application_controller.rb | 6 +++--- app/services/cnmoocs_service.rb | 5 +++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index 0be7d4b2..6085d00f 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -109,12 +109,12 @@ module Mobile return uw.user if uw end - third_party_user_id = session[:third_party_user_id] - Rails.logger.info("#########third_party_user_id: #{third_party_user_id}") - if third_party_user_id - c_user = UserSource.find_by_id(session[:third_party_user_id]) - return c_user.user if c_user - end + # third_party_user_id = session[:third_party_user_id] + # Rails.logger.info("#########third_party_user_id: #{third_party_user_id}") + # if third_party_user_id + # c_user = UserSource.find_by_id(session[:third_party_user_id]) + # return c_user.user if c_user + # end token = ApiKey.where(access_token: params[:token]).first if token && !token.expired? diff --git a/app/api/mobile/apis/cnmooc.rb b/app/api/mobile/apis/cnmooc.rb index b813d559..96b10101 100644 --- a/app/api/mobile/apis/cnmooc.rb +++ b/app/api/mobile/apis/cnmooc.rb @@ -43,10 +43,6 @@ module Mobile requires :accessType, type: Integer, desc: "资源类型" end get "source_url" do - if session[:third_party_user_id].blank? - user = User.find(params[:userId]) - session[:third_party_user_id] = user.user_source.id - end CnmoocsService.new.source_url(params) end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d1b7d21a..9018cc6c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -207,9 +207,9 @@ class ApplicationController < ActionController::Base elsif session[:wechat_openid] uw = UserWechat.find_by_openid(session[:wechat_openid]) user = uw.user if uw - elsif session[:third_party_user_id] - c_user = UserSource.find_by_id(session[:third_party_user_id]) - user = c_user.user if c_user + elsif params[:authToken] + user = Token.find_by_value(params[:authToken]).user + session[:user_id] = user.id end end if user.nil? && Setting.rest_api_enabled? && accept_api_auth? diff --git a/app/services/cnmoocs_service.rb b/app/services/cnmoocs_service.rb index 3161eeac..6de07203 100644 --- a/app/services/cnmoocs_service.rb +++ b/app/services/cnmoocs_service.rb @@ -115,12 +115,13 @@ class CnmoocsService end def source_url(params) + user = User.find_by_id(params[:userId]) + token = Token.get_or_create_permanent_login_token(user) shixun = Shixun.find_by_id(params[:resouceId]) if shixun.blank? return { error: -1, messages: '资源不存在' } end - - { error: 0, messages: '成功', accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}" } + { error: 0, messages: '成功', accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}/challenges?authToken=#{token.value}" } end def get_students_data params