From 8b716bf8afeadd079797f981c2871d0f90f28f03 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 13 Jun 2019 19:35:06 +0800 Subject: [PATCH] trainings: fix require login --- app/controllers/trainings_controller.rb | 26 +++++-------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/app/controllers/trainings_controller.rb b/app/controllers/trainings_controller.rb index 24638161..2542dbb5 100644 --- a/app/controllers/trainings_controller.rb +++ b/app/controllers/trainings_controller.rb @@ -3,6 +3,7 @@ require 'base64' class TrainingsController < ApplicationController wechat_responder + skip_before_filter :check_if_login_required skip_before_filter :verify_signature, only: [:show, :create, :update, :test, :enroll] ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}" @@ -225,7 +226,7 @@ class TrainingsController < ApplicationController # 用于权限跳转 def auth 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" redirect_to authorize_url end @@ -237,26 +238,9 @@ class TrainingsController < ApplicationController render 'wechats/open_wechat', layout: nil and return end - session[:wechat_open_id] = open_id - # 考虑状态 - # 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 - + redirect_to params[:return_url].present? ? params[:return_url] : '/' end def test @@ -270,11 +254,11 @@ class TrainingsController < ApplicationController def authenticate if Rails.env.development? - session[:wechat_open_id] = "o5fSc0607iR3rp4-h_VnuBTp8CiM" + # session[:wechat_open_id] = "o5fSc0607iR3rp4-h_VnuBTp8CiM" end unless session[:wechat_open_id].present? - redirect_to auth_trainings_path + redirect_to auth_trainings_path(return_url: CGI.escape(request.path)) end end