From 1fb7c35c30e73b1890a61718197e6ea8eb62f4de Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 28 May 2019 20:56:53 +0800 Subject: [PATCH] fix session --- app/api/mobile/api.rb | 6 ++++++ app/api/mobile/apis/cnmooc.rb | 5 +++++ app/services/cnmoocs_service.rb | 5 ----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index 958fe6a9..69bd4d44 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -109,6 +109,12 @@ module Mobile return uw.user if uw end + third_party_user_id = session[: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? return User.find(token.user_id) diff --git a/app/api/mobile/apis/cnmooc.rb b/app/api/mobile/apis/cnmooc.rb index 96b10101..d67a390d 100644 --- a/app/api/mobile/apis/cnmooc.rb +++ b/app/api/mobile/apis/cnmooc.rb @@ -43,6 +43,11 @@ 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/services/cnmoocs_service.rb b/app/services/cnmoocs_service.rb index 903db58d..caba8ebb 100644 --- a/app/services/cnmoocs_service.rb +++ b/app/services/cnmoocs_service.rb @@ -115,11 +115,6 @@ class CnmoocsService end def source_url(params) - if session[:third_party_user_id].blank? - user = User.find(params[:userId]) - session[:third_party_user_id] = user.user_source.id - end - shixun = Shixun.find_by_identifier(params[:resouceId]) if shixun.blank? return { error: -1, messages: '资源不存在' }