From 49c9e8ec02e5219cf984da61de52352ec5775c98 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 24 Jun 2014 14:16:52 +0200 Subject: [PATCH] Use an error page when oauth fails. --- app/controllers/omniauth_callbacks_controller.rb | 8 +++++++- config/routes.rb | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 477743b34c8..ef2afec52dc 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -31,6 +31,12 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController end end + def omniauth_error + @provider = params[:provider] + @error = params[:error] + render 'errors/omniauth_error', layout: "errors", status: 422 + end + private def handle_omniauth @@ -54,7 +60,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController else if errors error_message = errors.map{ |attribute, message| "#{attribute} #{message}" }.join(", ") - flash[:notice] = "There was a problem creating your account. #{error_message}" + redirect_to omniauth_error_path(oauth['provider'], error: error_message) and return else flash[:notice] = "There's no such user!" end diff --git a/config/routes.rb b/config/routes.rb index 5b854ed20b9..14ff52f387a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -160,6 +160,9 @@ Gitlab::Application.routes.draw do devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations , passwords: :passwords, sessions: :users_sessions } + devise_scope :user do + get "/users/auth/:provider/omniauth_error" => "omniauth_callbacks#omniauth_error", as: :omniauth_error + end # # Project Area #