module WechatGate::Controller::InstanceMethods
Protected Instance Methods
bind_user_with_open_id(user_model)
click to toggle source
# File lib/wechat_gate/controller.rb, line 49 def bind_user_with_open_id user_model if is_wechat_logged_in? and user_model.open_id.blank? user_model.update_attribute :open_id, current_open_id end end
check_wechat_server()
click to toggle source
# File lib/wechat_gate/controller.rb, line 65 def check_wechat_server unless is_legal_from_wechat_server? render text: "illegal signature!" end end
current_open_id()
click to toggle source
# File lib/wechat_gate/controller.rb, line 35 def current_open_id session[:user_open_id] end
is_legal_from_wechat_server?()
click to toggle source
# File lib/wechat_gate/controller.rb, line 55 def is_legal_from_wechat_server? data = [ wechat_gate_config.config["push_token"], params[:timestamp], params[:nonce] ] Digest::SHA1.hexdigest(data.sort.join('')) == params[:signature] end
is_wechat_logged_in?()
click to toggle source
# File lib/wechat_gate/controller.rb, line 31 def is_wechat_logged_in? !!session[:user_open_id] end
wechat_gate_config()
click to toggle source
# File lib/wechat_gate/controller.rb, line 27 def wechat_gate_config @wechat_gate_config ||= wechat_gate_setup end
wechat_gate_setup()
click to toggle source
# File lib/wechat_gate/controller.rb, line 19 def wechat_gate_setup unless self.class.wechat_gate_app_name raise Exception::ConfigException, "please specify wechat_gate_app_name!" end @wechat_gate_config = WechatGate::Config.new(self.class.wechat_gate_app_name) end
wechat_user_auth()
click to toggle source
# File lib/wechat_gate/controller.rb, line 43 def wechat_user_auth unless is_wechat_logged_in? redirect_to wechat_gate_config.oauth2_entrance_url(scope: "snsapi_base") end end
wechat_user_signin(user_open_id)
click to toggle source
# File lib/wechat_gate/controller.rb, line 39 def wechat_user_signin(user_open_id) session[:user_open_id] = user_open_id end