FEATURE: Support importing email from Twitter

This commit is contained in:
Robin Ward 2016-09-06 12:18:13 -04:00
parent acaac02673
commit 610dd933a3
1 changed files with 13 additions and 1 deletions

View File

@ -12,10 +12,15 @@ class Auth::TwitterAuthenticator < Auth::Authenticator
data = auth_token[:info]
result.email = data['email']
result.username = screen_name = data["nickname"]
result.name = name = data["name"]
result.name = data["name"]
twitter_user_id = auth_token["uid"]
if result.email.present?
result.email_valid = true
end
result.extra_data = {
twitter_user_id: twitter_user_id,
twitter_screen_name: screen_name
@ -24,6 +29,13 @@ class Auth::TwitterAuthenticator < Auth::Authenticator
user_info = TwitterUserInfo.find_by(twitter_user_id: twitter_user_id)
result.user = user_info.try(:user)
if !result.user && result.email.present? && result.user = User.find_by_email(result.email)
TwitterUserInfo.create(
user_id: result.user.id,
screen_name: screen_name,
twitter_user_id: twitter_user_id
)
end
result
end