Sha256: d9826095018cb84b37f1d8a54b73449f0e1a062bdcc76349aad3058788cc99e2

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module Omniauth
  class MultipleProvidersController < ApplicationController
    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

    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 prepare_path
      else
        sign_in(@user)
        redirect_to root_path, notice: 'OK'
      end
    end

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-multiple_providers-0.0.2 app/controllers/omniauth/multiple_providers_controller.rb
omniauth-multiple_providers-0.0.1 app/controllers/omniauth/multiple_providers_controller.rb