Return better error when account exists when attempting oauth account create.

This commit is contained in:
Marin Jankovski 2014-06-24 12:57:41 +02:00 committed by Dmitriy Zaporozhets
parent 2d9667df26
commit f40e87a03b
2 changed files with 16 additions and 5 deletions

View file

@ -45,14 +45,19 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
# Create user if does not exist
# and allow_single_sign_on is true
if Gitlab.config.omniauth['allow_single_sign_on']
@user ||= Gitlab::OAuth::User.create(oauth)
if Gitlab.config.omniauth['allow_single_sign_on'] && !@user
@user, errors = Gitlab::OAuth::User.create(oauth)
end
if @user
if @user && !errors
sign_in_and_redirect(@user)
else
flash[:notice] = "There's no such user!"
if errors
error_message = errors.map{ |attribute, message| "#{attribute} #{message}" }.join(", ")
flash[:notice] = "There was a problem creating your account. #{error_message}"
else
flash[:notice] = "There's no such user!"
end
redirect_to new_user_session_path
end
end

View file

@ -44,7 +44,13 @@ module Gitlab
user.username = email_username.gsub("'", "")
end
user.save!
begin
user.save!
rescue ActiveRecord::RecordInvalid => e
log.info "(OAuth) Email #{e.record.errors[:email]}. Username #{e.record.errors[:username]}"
return nil, e.record.errors
end
log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}"
if Gitlab.config.omniauth['block_auto_created_users'] && !ldap?