FIX: when associating Github account disassociate others

There are some cases where an email floats from one GitHub account to another
if this happens just take over the Github mapping record
This commit is contained in:
Sam
2018-10-10 15:46:50 +11:00
parent 59ce11d10c
commit 45f01e637b
2 changed files with 35 additions and 1 deletions

View File

@ -86,7 +86,12 @@ class Auth::GithubAuthenticator < Auth::Authenticator
if !!candidate[:verified] && (user = User.find_by_email(candidate[:email]))
result.email = candidate[:email]
result.email_valid = !!candidate[:verified]
GithubUserInfo.create(
GithubUserInfo
.where('user_id = ? OR github_user_id = ?', user.id, github_user_id)
.destroy_all
GithubUserInfo.create!(
user_id: user.id,
screen_name: screen_name,
github_user_id: github_user_id