auth: Extend the template for "choose email" in GitHub auth flow.

This commit extends the template for "choose email" to mention for
users who have unverified emails that they need to verify them before
using them for Zulip authentication.

Also modified `social_auth_test_finish` to assert if all emails
are present in "choose email" screen as we need unverified emails
to be shown to user and verified emails to login/signup.

Fixes #12638 as this was the last task for that issue.
This commit is contained in:
Dinesh
2020-03-28 15:29:06 +05:30
committed by Tim Abbott
parent 4a07a6def7
commit 5c1fe776c3
3 changed files with 72 additions and 3 deletions

View File

@@ -1093,10 +1093,15 @@ def social_associate_user_helper(backend: BaseAuth, return_data: Dict[str, Any],
if existing_account is not None:
existing_account_emails.append(email)
avatars[email] = avatar_url(existing_account)
if (len(existing_account_emails) != 1 or backend.strategy.session_get('is_signup') == '1'):
unverified_emails = []
if hasattr(backend, 'get_unverified_emails'):
unverified_emails = backend.get_unverified_emails(*args, **kwargs)
return render(backend.strategy.request, 'zerver/social_auth_select_email.html', context = {
'primary_email': verified_emails[0],
'verified_non_primary_emails': verified_emails[1:],
'unverified_emails': unverified_emails,
'backend': 'github',
'avatar_urls': avatars,
})
@@ -1374,6 +1379,13 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
emails = []
return emails
def get_unverified_emails(self, *args: Any, **kwargs: Any) -> List[str]:
emails = self.get_all_associated_email_objects(*args, **kwargs)
return [
email_obj['email'] for email_obj in emails
if not email_obj.get('verified') and not email_obj["email"].endswith("noreply.github.com")
]
def get_verified_emails(self, *args: Any, **kwargs: Any) -> List[str]:
emails = self.get_all_associated_email_objects(*args, **kwargs)
verified_emails: List[str] = []