Class: ClickfunnelsAuth::UserSessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/clickfunnels_auth/user_sessions_controller.rb

Instance Method Summary collapse

Methods included from ControllerHelper

#auth_redirect, #check_cookie, #cookie_valid?, #current_user, #is_token_older_than_current_login?, #login_required, #not_authorized, #signed_in?

Instance Method Details

#createObject

omniauth callback method



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/clickfunnels_auth/user_sessions_controller.rb', line 5

def create
  omniauth = request.env['omniauth.auth']
  puts "omniauth ============================================================="
  pp omniauth
  puts "======================================================================"
  puts "expires_at = #{omniauth['credentials']['expires_at']}"

  user = User.find_by_id(omniauth['uid'])
  if not user
    # New user registration
    user = User.new
    user.id = omniauth['uid']
  end
  user.email = omniauth['info']['email'] if user.respond_to?(:email)
  user.email = omniauth['info']['name']  if user.respond_to?(:name)
  user.save

  user.access_tokens.destroy_all

  user.access_tokens.create!({
    token: omniauth['credentials']['token'],
    refresh_token: omniauth['credentials']['refresh_token'],
    expires_at: omniauth['credentials']['expires_at'] ? Time.at(omniauth['credentials']['expires_at']) : omniauth['credentials']['expires_at']
  })

  session[:user_id] = user.id

  if block_given?
    yield omniauth
  end

  flash[:notice] = "Successfully logged in"
  #redirect_to request.env['omniauth.origin'] || root_path
  redirect_to session['origin'] || root_path
end

#destroyObject

logout - Clear our rack session BUT essentially redirect to the provider to clean up the Devise session from there too !



49
50
51
52
53
# File 'app/controllers/clickfunnels_auth/user_sessions_controller.rb', line 49

def destroy
  reset_session
  flash[:notice] = 'You have successfully signed out!'
  redirect_to "#{ENV['AUTH_PROVIDER_URL']}/users/sign_out"
end

#failureObject

Omniauth failure callback



42
43
44
45
# File 'app/controllers/clickfunnels_auth/user_sessions_controller.rb', line 42

def failure
  flash[:notice] = params[:message]
  redirect_to root_path
end