mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: Import facebook avatars when logging in via facebook
FIX: warning about popup dimensions when using facebook login Rules are: - On account creation we always import - If you already have an avatar uploaded, nothing is changed - If you have no avatar uploaded, we upload from facebook on login - If you have no avatar uploaded, we select facebook unless gravatar already selected This also fixes SSO issues where on account creation accounts had missing avatar uploads
This commit is contained in:
parent
72f9369966
commit
5b3cd3fac9
6 changed files with 83 additions and 7 deletions
|
@ -24,6 +24,17 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
|||
FacebookUserInfo.create({user_id: result.user.id}.merge(facebook_hash))
|
||||
end
|
||||
|
||||
if user_info
|
||||
user_info.update_columns(facebook_hash)
|
||||
end
|
||||
|
||||
user = result.user
|
||||
if user && (!user.user_avatar || user.user_avatar.custom_upload_id.nil?)
|
||||
if (avatar_url = facebook_hash[:avatar_url]).present?
|
||||
UserAvatar.import_url_for_user(avatar_url, user, override_gravatar: false)
|
||||
end
|
||||
end
|
||||
|
||||
if email.blank?
|
||||
UserHistory.create(
|
||||
action: UserHistory.actions[:facebook_no_email],
|
||||
|
@ -37,14 +48,24 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
|||
def after_create_account(user, auth)
|
||||
data = auth[:extra_data]
|
||||
FacebookUserInfo.create({user_id: user.id}.merge(data))
|
||||
|
||||
|
||||
if (avatar_url = data[:avatar_url]).present?
|
||||
UserAvatar.import_url_for_user(avatar_url, user)
|
||||
user.save
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def register_middleware(omniauth)
|
||||
|
||||
omniauth.provider :facebook,
|
||||
:setup => lambda { |env|
|
||||
strategy = env["omniauth.strategy"]
|
||||
strategy.options[:client_id] = SiteSetting.facebook_app_id
|
||||
strategy.options[:client_secret] = SiteSetting.facebook_app_secret
|
||||
strategy.options[:info_fields] = 'gender,email,name,bio,first_name,link,last_name'
|
||||
},
|
||||
:scope => "email"
|
||||
end
|
||||
|
@ -54,6 +75,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
|||
def parse_auth_token(auth_token)
|
||||
|
||||
raw_info = auth_token["extra"]["raw_info"]
|
||||
info = auth_token["info"]
|
||||
|
||||
email = auth_token["info"][:email]
|
||||
|
||||
{
|
||||
|
@ -65,7 +88,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
|||
last_name: raw_info["last_name"],
|
||||
email: email,
|
||||
gender: raw_info["gender"],
|
||||
name: raw_info["name"]
|
||||
name: raw_info["name"],
|
||||
avatar_url: info["image"]
|
||||
},
|
||||
email: email,
|
||||
email_valid: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue