Commit f40e87a0 authored by Marin Jankovski's avatar Marin Jankovski Committed by Dmitriy Zaporozhets

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

parent 2d9667df
......@@ -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
......
......@@ -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?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment