From 504bc58d47f733dc5da2714546ab0671b2f567e2 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 13 Dec 2017 18:38:21 +0100 Subject: [PATCH] Fixed issue #1710 - Unable to login with Office365. --- app/models/avatar.rb | 51 +++++++++++++------ db/migrate/20120101000001_create_base.rb | 2 +- ...3000001_change_authorization_token_size.rb | 10 ++++ 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20171213000001_change_authorization_token_size.rb diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 3bc1a9984..fb4b2793b 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -105,22 +105,41 @@ add avatar by url # fetch image based on http url if data[:url].present? - if data[:url].match?(/^http/) + if data[:url].class == Tempfile + logger.info "Reading image from tempfile '#{data[:url].inspect}'" + content = data[:url].read + filename = data[:url].path + mime_type = 'image' + if filename.match?(/\.png/i) + mime_type = 'image/png' + end + if filename.match?(/\.(jpg|jpeg)/i) + mime_type = 'image/jpeg' + end + data[:resize] ||= {} + data[:resize][:content] = content + data[:resize][:mime_type] = mime_type + data[:full] ||= {} + data[:full][:content] = content + data[:full][:mime_type] = mime_type + + elsif data[:url].to_s.match?(/^http/) + url = data[:url].to_s # check if source ist already updated within last 2 minutes - if avatar_already_exists&.source_url == data[:url] + if avatar_already_exists&.source_url == url return if avatar_already_exists.updated_at > 2.minutes.ago end # twitter workaround to get bigger avatar images # see also https://dev.twitter.com/overview/general/user-profile-images-and-banners - if data[:url].match?(%r{//pbs.twimg.com/}i) - data[:url].sub!(/normal\.(png|jpg|gif)$/, 'bigger.\1') + if url.match?(%r{//pbs.twimg.com/}i) + url.sub!(/normal\.(png|jpg|gif)$/, 'bigger.\1') end # fetch image response = UserAgent.get( - data[:url], + url, {}, { open_timeout: 4, @@ -129,20 +148,19 @@ add avatar by url }, ) if !response.success? - logger.info "Can't fetch '#{data[:url]}' (maybe no avatar available), http code: #{response.code}" + logger.info "Can't fetch '#{url}' (maybe no avatar available), http code: #{response.code}" return end - logger.info "Fetchd image '#{data[:url]}', http code: #{response.code}" + logger.info "Fetchd image '#{url}', http code: #{response.code}" mime_type = 'image' - if data[:url].match?(/\.png/i) + if url.match?(/\.png/i) mime_type = 'image/png' end - if data[:url].match?(/\.(jpg|jpeg)/i) + if url.match?(/\.(jpg|jpeg)/i) mime_type = 'image/jpeg' end - if !data[:resize] - data[:resize] = {} - end + + data[:resize] ||= {} data[:resize][:content] = response.body data[:resize][:mime_type] = mime_type data[:full] ||= {} @@ -150,15 +168,16 @@ add avatar by url data[:full][:mime_type] = mime_type # try zammad backend to find image based on email - elsif data[:url].match?(/@/) + elsif data[:url].to_s.match?(/@/) + url = data[:url].to_s # check if source ist already updated within last 3 minutes - if avatar_already_exists&.source_url == data[:url] + if avatar_already_exists&.source_url == url return if avatar_already_exists.updated_at > 2.minutes.ago end # fetch image - image = Service::Image.user(data[:url]) + image = Service::Image.user(url) return if !image data[:resize] ||= {} data[:resize] = image @@ -337,7 +356,7 @@ returns: store_hash: hash, ) return if !avatar - file = Store.find(avatar.store_resize_id) + Store.find(avatar.store_resize_id) end =begin diff --git a/db/migrate/20120101000001_create_base.rb b/db/migrate/20120101000001_create_base.rb index c74f50836..01834da3c 100644 --- a/db/migrate/20120101000001_create_base.rb +++ b/db/migrate/20120101000001_create_base.rb @@ -201,7 +201,7 @@ class CreateBase < ActiveRecord::Migration[4.2] create_table :authorizations do |t| t.string :provider, limit: 250, null: false t.string :uid, limit: 250, null: false - t.string :token, limit: 250, null: true + t.string :token, limit: 2500, null: true t.string :secret, limit: 250, null: true t.string :username, limit: 250, null: true t.references :user, null: false diff --git a/db/migrate/20171213000001_change_authorization_token_size.rb b/db/migrate/20171213000001_change_authorization_token_size.rb new file mode 100644 index 000000000..34a71e23f --- /dev/null +++ b/db/migrate/20171213000001_change_authorization_token_size.rb @@ -0,0 +1,10 @@ +class ChangeAuthorizationTokenSize < ActiveRecord::Migration[5.1] + def up + # return if it's a new setup to avoid running the migration + return if !Setting.find_by(name: 'system_init_done') + + change_column :authorizations, :token, :string, limit: 2500 + + end + +end