FIX: don't suggest a username that's already taken, even if hub finds a match

This commit is contained in:
Neil Lalonde 2013-11-20 14:56:01 -05:00
parent 97cb9e1545
commit 69cc1dd689
2 changed files with 14 additions and 1 deletions

View File

@ -11,7 +11,12 @@ class UsernameCheckerService
check_username_with_hub_server(username, email)
end
elsif email and SiteSetting.call_discourse_hub?
{suggestion: DiscourseHub.nickname_for_email(email)}
username_from_hub = DiscourseHub.nickname_for_email(email)
if username_from_hub && User.username_available?(username_from_hub)
{suggestion: username_from_hub}
else
{suggestion: nil}
end
end
end

View File

@ -95,6 +95,14 @@ describe UsernameCheckerService do
DiscourseHub.stubs(:nickname_for_email).returns('vincent')
result.should == {suggestion: 'vincent'}
end
it 'match found for email, but username is taken' do
# This case can happen when you've already signed up on the site,
# or enforce_global_nicknames used to be disabled.
DiscourseHub.stubs(:nickname_for_email).returns('taken')
User.stubs(:username_available?).with('taken').returns(false)
result.should == {suggestion: nil}
end
end
context 'username is nil' do