Fixed issue #1710 - Unable to login with Office365.
This commit is contained in:
parent
97a5cd3cf5
commit
504bc58d47
3 changed files with 46 additions and 17 deletions
|
@ -105,22 +105,41 @@ add avatar by url
|
||||||
|
|
||||||
# fetch image based on http url
|
# fetch image based on http url
|
||||||
if data[:url].present?
|
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
|
# 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
|
return if avatar_already_exists.updated_at > 2.minutes.ago
|
||||||
end
|
end
|
||||||
|
|
||||||
# twitter workaround to get bigger avatar images
|
# twitter workaround to get bigger avatar images
|
||||||
# see also https://dev.twitter.com/overview/general/user-profile-images-and-banners
|
# see also https://dev.twitter.com/overview/general/user-profile-images-and-banners
|
||||||
if data[:url].match?(%r{//pbs.twimg.com/}i)
|
if url.match?(%r{//pbs.twimg.com/}i)
|
||||||
data[:url].sub!(/normal\.(png|jpg|gif)$/, 'bigger.\1')
|
url.sub!(/normal\.(png|jpg|gif)$/, 'bigger.\1')
|
||||||
end
|
end
|
||||||
|
|
||||||
# fetch image
|
# fetch image
|
||||||
response = UserAgent.get(
|
response = UserAgent.get(
|
||||||
data[:url],
|
url,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
open_timeout: 4,
|
open_timeout: 4,
|
||||||
|
@ -129,20 +148,19 @@ add avatar by url
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if !response.success?
|
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
|
return
|
||||||
end
|
end
|
||||||
logger.info "Fetchd image '#{data[:url]}', http code: #{response.code}"
|
logger.info "Fetchd image '#{url}', http code: #{response.code}"
|
||||||
mime_type = 'image'
|
mime_type = 'image'
|
||||||
if data[:url].match?(/\.png/i)
|
if url.match?(/\.png/i)
|
||||||
mime_type = 'image/png'
|
mime_type = 'image/png'
|
||||||
end
|
end
|
||||||
if data[:url].match?(/\.(jpg|jpeg)/i)
|
if url.match?(/\.(jpg|jpeg)/i)
|
||||||
mime_type = 'image/jpeg'
|
mime_type = 'image/jpeg'
|
||||||
end
|
end
|
||||||
if !data[:resize]
|
|
||||||
data[:resize] = {}
|
data[:resize] ||= {}
|
||||||
end
|
|
||||||
data[:resize][:content] = response.body
|
data[:resize][:content] = response.body
|
||||||
data[:resize][:mime_type] = mime_type
|
data[:resize][:mime_type] = mime_type
|
||||||
data[:full] ||= {}
|
data[:full] ||= {}
|
||||||
|
@ -150,15 +168,16 @@ add avatar by url
|
||||||
data[:full][:mime_type] = mime_type
|
data[:full][:mime_type] = mime_type
|
||||||
|
|
||||||
# try zammad backend to find image based on email
|
# 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
|
# 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
|
return if avatar_already_exists.updated_at > 2.minutes.ago
|
||||||
end
|
end
|
||||||
|
|
||||||
# fetch image
|
# fetch image
|
||||||
image = Service::Image.user(data[:url])
|
image = Service::Image.user(url)
|
||||||
return if !image
|
return if !image
|
||||||
data[:resize] ||= {}
|
data[:resize] ||= {}
|
||||||
data[:resize] = image
|
data[:resize] = image
|
||||||
|
@ -337,7 +356,7 @@ returns:
|
||||||
store_hash: hash,
|
store_hash: hash,
|
||||||
)
|
)
|
||||||
return if !avatar
|
return if !avatar
|
||||||
file = Store.find(avatar.store_resize_id)
|
Store.find(avatar.store_resize_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
|
@ -201,7 +201,7 @@ class CreateBase < ActiveRecord::Migration[4.2]
|
||||||
create_table :authorizations do |t|
|
create_table :authorizations do |t|
|
||||||
t.string :provider, limit: 250, null: false
|
t.string :provider, limit: 250, null: false
|
||||||
t.string :uid, 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 :secret, limit: 250, null: true
|
||||||
t.string :username, limit: 250, null: true
|
t.string :username, limit: 250, null: true
|
||||||
t.references :user, null: false
|
t.references :user, null: false
|
||||||
|
|
10
db/migrate/20171213000001_change_authorization_token_size.rb
Normal file
10
db/migrate/20171213000001_change_authorization_token_size.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue