Class: AuthenticationsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/authentications_controller.rb', line 6

def create
  omniauth = request.env["omniauth.auth"]
  authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
  if authentication
    flash[:notice] = "Signed in successfully."
    (:user, authentication.user)
  elsif current_user
    current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
    flash[:notice] = "Authentication successful"
    redirect_to authentications_url
  else
    user = User.new
    user.apply_omniauth(omniauth)
    if user.save
      flash[:notice] = "Signed in successfully."
      (:user, user)
    else
      session[:omniauth] = omniauth.except('extra')
      redirect_to new_user_registration_url
    end
  end
end

#destroyObject



29
30
31
32
33
# File 'app/controllers/authentications_controller.rb', line 29

def destroy
  @authentication = current_user.authentications.find(params[:id])
  @authentication.destroy
  redirect_to authentications_url, :notice => "Successfully destroyed authentication."
end

#indexObject



2
3
4
# File 'app/controllers/authentications_controller.rb', line 2

def index
  @authentications = current_user.authentications if current_user
end