Module: ClickfunnelsAuth::ControllerHelper
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- lib/clickfunnels_auth/controller_helper.rb
Instance Method Summary collapse
- #auth_redirect ⇒ Object
- #check_cookie ⇒ Object
- #cookie_valid? ⇒ Boolean
- #current_user ⇒ Object
- #is_token_older_than_current_login?(token) ⇒ Boolean
- #login_required ⇒ Object
- #not_authorized ⇒ Object
- #signed_in? ⇒ Boolean
Instance Method Details
#auth_redirect ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 46 def auth_redirect origin = "#{request.protocol}#{request.host_with_port}#{request.fullpath}" # Currently Doorkeeper has a bug when the redirct contains query params, so for now # we'll put the origin in the session instead of the redirect url. #observable_redirect_to "/auth/clickfunnels?origin=#{CGI.escape(origin)}" session['origin'] = origin if ENV['ENABLE_FAKE_AUTH'] == 'true' observable_redirect_to "/fake_auth" else observable_redirect_to "/auth/clickfunnels" end end |
#check_cookie ⇒ Object
14 15 16 17 18 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 14 def if ! session[:user_id] = nil end end |
#cookie_valid? ⇒ Boolean
20 21 22 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 20 def [:clickfunnels_login_user].present? && session[:user_id].present? && [:clickfunnels_login_user].to_s == session[:user_id].to_s end |
#current_user ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 59 def current_user return nil unless session[:user_id] @current_user ||= User.find_by_id(session[:user_id]) token = @current_user.access_tokens.first puts "token = #{token}" puts "token.expired? = #{token.try :expired?}" if token.blank? puts "*******************************************************" puts "we had a user, but they did not have a token!" puts "*******************************************************" session[:user_id] = nil return nil elsif token.expired? || is_token_older_than_current_login?(token) begin puts "*******************************************************" puts "aobut to refresh the token!" puts "token.expired? : #{token.expired?}" puts "is_token_older_than_current_login?(token) : #{is_token_older_than_current_login?(token)}" puts "*******************************************************" token.refresh! rescue OAuth2::Error => e puts "caught error #{e}" token.destroy! session[:user_id] = nil return nil end end return @current_user end |
#is_token_older_than_current_login?(token) ⇒ Boolean
37 38 39 40 41 42 43 44 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 37 def is_token_older_than_current_login?(token) return false # TODO : We need to get the mothership setting this and the clickfunnels_login_user cookie if ![:clickfunnels_login_timestamp].present? return true end return token.updated_at < Time.at([:clickfunnels_login_timestamp].to_i) end |
#login_required ⇒ Object
24 25 26 27 28 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 24 def login_required if !current_user end end |
#not_authorized ⇒ Object
30 31 32 33 34 35 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 30 def respond_to do |format| format.html{ auth_redirect } format.json{ head :unauthorized } end end |
#signed_in? ⇒ Boolean
89 90 91 |
# File 'lib/clickfunnels_auth/controller_helper.rb', line 89 def signed_in? current_user.present? end |