From 20eabc1e5bc502e36c1b3f3ed4fa259c23b62bc3 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 1 Sep 2015 14:41:37 +0800 Subject: Bug 1200515 - unable to create accounts with github --- extensions/GitHubAuth/lib/Login.pm | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/extensions/GitHubAuth/lib/Login.pm b/extensions/GitHubAuth/lib/Login.pm index 933dc6572..6e105c33a 100644 --- a/extensions/GitHubAuth/lib/Login.pm +++ b/extensions/GitHubAuth/lib/Login.pm @@ -54,17 +54,28 @@ sub get_login_info { } if (!exists $response->{failure}) { - my $user = $response->{user}; - return { failure => AUTH_ERROR, - user_error => 'github_auth_account_too_powerful' } if $user->in_group('no-github-auth'); - return { failure => AUTH_ERROR, - user_error => 'mfa_prevents_login', - details => { provider => 'GitHub' } } if $user->mfa; - $response = { - username => $user->login, - user_id => $user->id, - github_auth => 1, - }; + if (exists $response->{user}) { + # existing account + my $user = $response->{user}; + return { failure => AUTH_ERROR, + user_error => 'github_auth_account_too_powerful' } if $user->in_group('no-github-auth'); + return { failure => AUTH_ERROR, + user_error => 'mfa_prevents_login', + details => { provider => 'GitHub' } } if $user->mfa; + $response = { + username => $user->login, + user_id => $user->id, + github_auth => 1, + }; + } + else { + # new account + my $email = $response->{email}; + $response = { + username => $email, + github_auth => 1, + }; + } } return $response; } @@ -177,7 +188,7 @@ sub _get_login_info_from_email { my $user = Bugzilla::User->new({name => $github_email, cache => 1}); $cgi->remove_cookie('Bugzilla_github_token'); - return { user => $user }; + return $user ? { user => $user } : { email => $github_email }; } sub fail_nodata { -- cgit v1.2.3-24-g4f1b