Class: Omniauth::MultipleProvidersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Omniauth::MultipleProvidersController
- Defined in:
- app/controllers/omniauth/multiple_providers_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#destroy ⇒ Object
PATH: omniauth_path(‘twitter’), method: :delete.
- #failure ⇒ Object
-
#new ⇒ Object
PATH: new_omniauth_path(provider: ‘twitter’).
Instance Method Details
#create ⇒ Object
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..join(', ')}"} elsif @user.email.blank? redirect_to new_user_registration_path(@user) else sign_in(@user) redirect_to after_sign_in_path_for(:user), notice: 'OK' end end |
#destroy ⇒ Object
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 |
#failure ⇒ Object
25 26 27 |
# File 'app/controllers/omniauth/multiple_providers_controller.rb', line 25 def failure redirect_to root_path, flash: {error: 'OAuth認証に失敗しました'} end |
#new ⇒ Object
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 |