Class: Devbootcamp::Rails::AuthenticationController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/devbootcamp/rails/authentication_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



28
29
30
31
# File 'lib/devbootcamp/rails/authentication_controller.rb', line 28

def destroy
  unauthenticate!
  redirect_to devbootcamp_oauth_unauthorize_url
end

#newObject



5
6
7
8
9
10
11
12
13
# File 'lib/devbootcamp/rails/authentication_controller.rb', line 5

def new
  destination_url = params[:r] || root_url
  if authenticated?
    redirect_to destination_url
  else
    session[:post_authorization_destination_url] = destination_url
    redirect_to devbootcamp_oauth_authorize_url
  end
end

#oauth_callbackObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/devbootcamp/rails/authentication_controller.rb', line 15

def oauth_callback
  oauth_code = params[:code]

  if Devbootcamp::OAuth.authorize!(oauth_code)
    self.current_user = Devbootcamp::User.me
    session[:oauth_token] = Devbootcamp::OAuth.token_as_hash
    flash[:notice] = "Welcome back #{current_user.name}"
  else
    flash[:error] = 'Authorization Failed'
  end
  redirect_to session[:post_authorization_destination_url] || root_url
end