Merge branch 'dev_trainings' into develop

dev_trainings
p31729568 6 years ago
commit d387cbd409

@ -3,6 +3,7 @@ require 'base64'
class TrainingsController < ApplicationController class TrainingsController < ApplicationController
wechat_responder wechat_responder
skip_before_filter :check_if_login_required
skip_before_filter :verify_signature, only: [:show, :create, :update, :test, :enroll] skip_before_filter :verify_signature, only: [:show, :create, :update, :test, :enroll]
ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}" ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}"
@ -225,7 +226,7 @@ class TrainingsController < ApplicationController
# 用于权限跳转 # 用于权限跳转
def auth def auth
state = params[:state] state = params[:state]
url = "#{ROOT_URL}/trainings/auth_callback" url = CGI.escape("#{ROOT_URL}/trainings/auth_callback?return_url=#{params[:return_url]}")
authorize_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{url}&response_type=code&scope=snsapi_base&state=#{state}&connect_redirect=1#wechat_redirect" authorize_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{url}&response_type=code&scope=snsapi_base&state=#{state}&connect_redirect=1#wechat_redirect"
redirect_to authorize_url redirect_to authorize_url
end end
@ -237,26 +238,9 @@ class TrainingsController < ApplicationController
render 'wechats/open_wechat', layout: nil and return render 'wechats/open_wechat', layout: nil and return
end end
session[:wechat_open_id] = open_id session[:wechat_open_id] = open_id
# 考虑状态 redirect_to params[:return_url].present? ? params[:return_url] : '/'
# 1. 无记录或未支付
# 2. 已填写未付款
#
@training = current_training
url = ''
if !@training
url = training_path(id: @tag_id)
elsif !@training.pay?
url = enroll_training_path(id: @tag_id)
else
url = result_training_path(id: @tag_id)
end
redirect_to url
end end
def test def test
@ -270,11 +254,11 @@ class TrainingsController < ApplicationController
def authenticate def authenticate
if Rails.env.development? if Rails.env.development?
session[:wechat_open_id] = "o5fSc0607iR3rp4-h_VnuBTp8CiM" # session[:wechat_open_id] = "o5fSc0607iR3rp4-h_VnuBTp8CiM"
end end
unless session[:wechat_open_id].present? unless session[:wechat_open_id].present?
redirect_to auth_trainings_path redirect_to auth_trainings_path(return_url: CGI.escape(request.path))
end end
end end

Loading…
Cancel
Save