diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index a0004c3c..0be7d4b2 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -108,6 +108,14 @@ module Mobile uw = UserWechat.find_by_openid(openid) 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 + 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 2d1f41b3..b813d559 100644 --- a/app/api/mobile/apis/cnmooc.rb +++ b/app/api/mobile/apis/cnmooc.rb @@ -43,10 +43,9 @@ module Mobile requires :accessType, type: Integer, desc: "资源类型" end get "source_url" do - if session[:user_id].blank? + if session[:third_party_user_id].blank? user = User.find(params[:userId]) - return { error: -1, messages: "用户不存在,请先创建用户" } unless user.user_source - session[:user_id] = user.id + session[:third_party_user_id] = user.user_source.id end CnmoocsService.new.source_url(params) end diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 6409114f..60096a22 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -293,7 +293,6 @@ class AccountController < ApplicationController UserActions.create(:action_id => User.current.id, :action_type => "Logout", :user_id => User.current.id) logout_user # 记录用户登出行为 - logger.info("#########logout_session: #{session}") redirect_to home_path end # display the logout form diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 435c71fc..d1b7d21a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -207,6 +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 end end if user.nil? && Setting.rest_api_enabled? && accept_api_auth? @@ -300,6 +303,7 @@ class ApplicationController < ActionController::Base end # Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) self.logged_user = nil + session[:third_party_user_id] = nil end end