mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 09:08:10 +08:00
FEATURE: optionally get extra profile info from facebook
This feature requires the application be approved by facebook, so it is default off
This commit is contained in:
@ -35,6 +35,20 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
bio = facebook_hash[:about_me]
|
||||
location = facebook_hash[:location]
|
||||
website = facebook_hash[:website]
|
||||
|
||||
if user && (bio || location || website)
|
||||
profile = user.user_profile
|
||||
|
||||
profile.bio_raw = bio unless profile.bio_raw.present?
|
||||
profile.location = location unless profile.location.present?
|
||||
profile.website = website unless profile.website.present?
|
||||
profile.save
|
||||
end
|
||||
|
||||
if email.blank?
|
||||
UserHistory.create(
|
||||
action: UserHistory.actions[:facebook_no_email],
|
||||
@ -55,6 +69,17 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
||||
user.save
|
||||
end
|
||||
|
||||
bio = data[:about_me]
|
||||
location = data[:location]
|
||||
website = data[:website]
|
||||
|
||||
if bio || location || website
|
||||
user.user_profile.bio_raw = bio
|
||||
user.user_profile.location = location
|
||||
user.user_profile.website = website
|
||||
user.user_profile.save
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
@ -65,7 +90,10 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
||||
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'
|
||||
strategy.options[:info_fields] = 'gender,email,name,bio,first_name,link,last_name,website,location'
|
||||
if SiteSetting.facebook_request_extra_profile_details
|
||||
strategy.options[:scope] = 'email,user_about_me,user_location,user_website'
|
||||
end
|
||||
},
|
||||
:scope => "email"
|
||||
end
|
||||
@ -79,6 +107,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
||||
|
||||
email = auth_token["info"][:email]
|
||||
|
||||
website = (info["urls"] && info["urls"]["Website"]) || nil
|
||||
|
||||
{
|
||||
facebook: {
|
||||
facebook_user_id: auth_token["uid"],
|
||||
@ -89,7 +119,10 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
||||
email: email,
|
||||
gender: raw_info["gender"],
|
||||
name: raw_info["name"],
|
||||
avatar_url: info["image"]
|
||||
avatar_url: info["image"],
|
||||
location: info["location"],
|
||||
website: website,
|
||||
about_me: info["description"]
|
||||
},
|
||||
email: email,
|
||||
email_valid: true
|
||||
|
Reference in New Issue
Block a user