Class: AuthenticationsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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
# File 'app/controllers/authentications_controller.rb', line 9

def create  
  omniauth = request.env["omniauth.auth"]
  if omniauth
    uid = (omniauth['uid']||omniauth['extra']['access_token'].params['member_id'])
    authentication = Authentication.find_by_provider_and_authenticationable_type_and_uid(omniauth['provider'], uid)
    if authentication
      flash[:notice] = "Signed in successfully."  
      (:user, authentication.user)
    elsif current_user
      current_user.authentications.create!(:provider => omniauth['provider'], :uid => uid, :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'])
      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  
  else
    redirect_to root_url
  end
end

#destroyObject



37
38
39
40
41
42
# File 'app/controllers/authentications_controller.rb', line 37

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

#indexObject



5
6
7
# File 'app/controllers/authentications_controller.rb', line 5

def index  
  @authentications = current_user.authentications if current_user  
end