pre_develop
daiao 6 years ago
parent 151ab55dbb
commit 2df0d65ce7

@ -43,7 +43,21 @@ module Mobile
requires :accessType, type: Integer, desc: "资源类型"
end
get "source_url" do
CnmoocsService.new.source_url(params)
user = User.find_by_id(params[:userId])
return {error: -1, messages: "用户不存在,请先创建用户"} unless user
token = Token.get_or_create_permanent_login_token(user)
cookie_options = {
:value => token.value,
:expires => 1.month.from_now,
:path => (Redmine::Configuration['autologin_cookie_path'] || '/'),
:secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false),
:httponly => true
}
if Redmine::Configuration['cookie_domain'].present?
cookie_options = cookie_options.merge(domain: Redmine::Configuration['cookie_domain'])
end
cookies[Redmine::Configuration['autologin_cookie_name'].presence || 'autologin'] = cookie_options
CnmoocsService.new.source_url(params, token)
end
desc "远程登录"

@ -224,8 +224,9 @@ class ApplicationController < ActionController::Base
user = uw.user if uw
elsif params[:authToken]
user = Token.find_by_value(params[:authToken]).user
set_autologin_cookie(user)
start_user_session(user)
#set_autologin_cookie(user)
#start_user_session(user)
session[:user_id] = user.id
end
end
if user.nil? && Setting.rest_api_enabled? && accept_api_auth?

@ -16,6 +16,7 @@ class ChallengesController < ApplicationController
#before_filter :find_shixun_language, :only => [:show, :new, :edit]
before_filter :base_index, :only => [:index, :index_down, :index_up, :destroy]
before_filter :view_allow, :only => [:show]
# before_filter :check_cnmooc, :only => [:index]
include ApplicationHelper
@ -487,4 +488,12 @@ class ChallengesController < ApplicationController
response.headers['content--type'] = 'text/javascript'
request.format = 'js'
end
# def check_cnmooc
# if params[:authToken]
# user = User.find_by_id(session[:user_id])
# set_autologin_cookie(user)
# end
# end
end

@ -114,10 +114,7 @@ class CnmoocsService
end
def source_url(params)
user = User.find_by_id(params[:userId])
return {error: -1, messages: "用户不存在,请先创建用户"} unless user
token = Token.get_or_create_permanent_login_token(user)
def source_url(params, token)
shixun = Shixun.find_by_id(params[:resouceId])
if shixun.blank?
return { error: -1, messages: '资源不存在' }

Loading…
Cancel
Save