Class: Omniauth::MultipleProvidersController

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

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/omniauth/multiple_providers_controller.rb', line 13

def create
  @user = User.find_or_create_by_oauth(env['omniauth.auth'], current_user)
  if @user.new_record?
    redirect_to new_user_session_path, flash: {error: "ユーザデータの保存に失敗しました:#{@user.errors.full_messages.join(', ')}"}
  elsif @user.email.blank?
    redirect_to new_user_registration_path(@user)
  else
    (@user)
    redirect_to (:user), notice: 'OK'
  end
end

#destroyObject

PATH: omniauth_path(‘twitter’), method: :delete



30
31
32
33
34
35
36
37
# File 'app/controllers/omniauth/multiple_providers_controller.rb', line 30

def destroy
  if up = current_user.provider_users.find_by(provider: params[:id])
    up.destroy
    redirect_to root_path, notice: "#{up.provider}の認証を削除しました。"
  else
    redirect_to root_path, notice: 'Does not exist your provider ID'
  end
end

#failureObject



25
26
27
# File 'app/controllers/omniauth/multiple_providers_controller.rb', line 25

def failure
  redirect_to root_path, flash: {error: 'OAuth認証に失敗しました'}
end

#newObject

PATH: new_omniauth_path(provider: ‘twitter’)



5
6
7
8
9
10
11
# File 'app/controllers/omniauth/multiple_providers_controller.rb', line 5

def new
  if %w[twitter github google_oauth2 facebook].include?(params[:provider])
    redirect_to "/auth/#{params[:provider]}"
  else
    redirect_to root_path, error: "#{params[:provider]}による認証は存在しません"
  end
end