Compare commits
2 Commits
17ffbde03a
...
46b908839d
| Author | SHA1 | Date | |
|---|---|---|---|
|
46b908839d
|
|||
|
512f0ccca1
|
@@ -9,13 +9,5 @@ module AppCatalog
|
||||
@image_url = image_url_for(web_app.apple_touch_icon)
|
||||
end
|
||||
end
|
||||
|
||||
def image_url_for(attachment)
|
||||
if Setting.s3_enabled?
|
||||
s3_image_url(attachment)
|
||||
else
|
||||
Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
20
app/controllers/avatars_controller.rb
Normal file
20
app/controllers/avatars_controller.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class AvatarsController < ApplicationController
|
||||
def show
|
||||
if user = User.find_by(cn: params[:username])
|
||||
http_status :not_found and return unless user.avatar.attached?
|
||||
|
||||
sha256_hash = params[:hash]
|
||||
format = params[:format].to_sym || :png
|
||||
size = params[:size]&.to_sym || :large
|
||||
|
||||
unless user.avatar_filename == "#{sha256_hash}.#{format}"
|
||||
http_status :not_found and return
|
||||
end
|
||||
|
||||
send_file user.avatar.service.path_for(user.avatar.key),
|
||||
disposition: "inline", type: "image/#{format}"
|
||||
else
|
||||
http_status :not_found and return
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,6 +8,9 @@ class Discourse::SsoController < ApplicationController
|
||||
sso.email = current_user.email
|
||||
sso.username = current_user.cn
|
||||
sso.name = current_user.display_name
|
||||
if current_user.avatar.attached?
|
||||
sso.avatar_url = helpers.image_url_for(current_user.avatar)
|
||||
end
|
||||
sso.admin = current_user.is_admin?
|
||||
sso.sso_secret = secret
|
||||
|
||||
|
||||
@@ -14,4 +14,12 @@ module ApplicationHelper
|
||||
def badge(text, color)
|
||||
tag.span text, class: "inline-flex items-center rounded-full bg-#{color}-100 px-2.5 py-0.5 text-xs font-medium text-#{color}-800"
|
||||
end
|
||||
|
||||
def image_url_for(attachment)
|
||||
if Setting.s3_enabled?
|
||||
s3_image_url(attachment)
|
||||
else
|
||||
Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,6 +15,9 @@ Rails.application.routes.draw do
|
||||
match 'signup/:step', to: 'signup#steps', as: :signup_steps, via: [:get, :post]
|
||||
post 'signup_validate', to: 'signup#validate'
|
||||
|
||||
|
||||
get "users/:username/avatars/:hash", to: "avatars#show", as: :user_avatar
|
||||
|
||||
namespace :contributions do
|
||||
root to: 'donations#index'
|
||||
resources :donations, only: ['index', 'create'] do
|
||||
|
||||
Reference in New Issue
Block a user