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:
Sam
2016-09-19 15:10:02 +10:00
parent 72f9369966
commit 5b3cd3fac9
6 changed files with 83 additions and 7 deletions

View File

@@ -130,7 +130,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
if(customLogin){
customLogin();
} else {
const authUrl = loginMethod.get('customUrl') || Discourse.getURL("/auth/" + name);
let authUrl = loginMethod.get('customUrl') || Discourse.getURL("/auth/" + name);
if (loginMethod.get("fullScreenLogin")) {
document.cookie = "fsl=true";
window.location = authUrl;
@@ -141,6 +141,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
const height = loginMethod.get("frameHeight") || 400;
const width = loginMethod.get("frameWidth") || 800;
if (loginMethod.get("displayPopup")) {
authUrl = authUrl + "?display=popup";
}
const w = window.open(authUrl, "_blank",
"menubar=no,status=no,height=" + height + ",width=" + width + ",left=" + left + ",top=" + top);
const self = this;

View File

@@ -34,7 +34,9 @@ export function findAll(siteSettings, capabilities, isMobileDevice) {
params.frameWidth = 850;
params.frameHeight = 500;
} else if (name === "facebook") {
params.frameHeight = 450;
params.frameWidth= 580;
params.frameHeight = 400;
params.displayPopup = true;
}
params.siteSettings = siteSettings;

View File

@@ -60,23 +60,33 @@ class UserAvatar < ActiveRecord::Base
"#{upload_id}_#{OptimizedImage::VERSION}"
end
def self.import_url_for_user(avatar_url, user)
def self.import_url_for_user(avatar_url, user, options=nil)
tempfile = FileHelper.download(avatar_url, SiteSetting.max_image_size_kb.kilobytes, "sso-avatar", true)
ext = FastImage.type(tempfile).to_s
tempfile.rewind
upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, File.size(tempfile.path), origin: avatar_url, image_type: "avatar")
user.uploaded_avatar_id = upload.id
unless user.user_avatar
user.build_user_avatar
user.create_user_avatar
end
if !user.user_avatar.contains_upload?(upload.id)
user.user_avatar.custom_upload_id = upload.id
user.user_avatar.update_columns(custom_upload_id: upload.id)
override_gravatar = !options || options[:override_gravatar]
if user.uploaded_avatar_id.nil? ||
!user.user_avatar.contains_upload?(user.uploaded_avatar_id) ||
override_gravatar
user.update_columns(uploaded_avatar_id: upload.id)
end
end
rescue => e
p e
# skip saving, we are not connected to the net
Rails.logger.warn "#{e}: Failed to download external avatar: #{avatar_url}, user id #{ user.id }"
ensure