Prefer to use primary email for new user creation over other available emails

This commit is contained in:
Vinoth Kannan
2018-03-19 17:10:35 +05:30
parent 19a93b0e95
commit c5d26992d4
2 changed files with 28 additions and 0 deletions

View File

@ -47,6 +47,8 @@ class Auth::GithubAuthenticator < Auth::Authenticator
# Potentially use *any* of the emails from GitHub to find a match or
# register a new user, with preference given to the primary email.
all_emails = Array.new(auth_token[:extra][:all_emails])
primary = all_emails.detect { |email| email[:primary] && email[:verified] }
all_emails.unshift(primary) if primary.present?
# Only consider verified emails to match an existing user. We don't want
# someone to be able to create a GitHub account with an unverified email