Support Users Directly Uploading Profile Pictures.

* Adds a `picture` attribute to `User`.
* Preserves Gravatar as a fallback option.
* Now, you should use `user.profile_picturer` instead of `gravatar_url`
* TODO: Ensure `profile_picture` handles sizing right for uploaded images.
This commit is contained in:
Michael Ball 2020-07-14 21:06:15 -07:00
parent b66f69599a
commit 3883188dcd
13 changed files with 43 additions and 18 deletions

View file

@ -23,9 +23,13 @@ class User < ApplicationRecord
has_paper_trail on: [:create, :update], ignore: [:sign_in_count, :remember_created_at, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip, :unconfirmed_email,
:avatar_content_type, :avatar_file_size, :avatar_updated_at, :updated_at, :confirmation_sent_at, :confirmation_token, :reset_password_token]
# A user may have an uploaded avatar or use gravatar.
# The uploaded picture takes precedence.
include Gravtastic
gravtastic size: 32
mount_uploader :picture, PictureUploader, mount_on: :picture
before_create :setup_role
after_save :touch_events
@ -151,6 +155,14 @@ class User < ApplicationRecord
ticket_purchases.find_by(conference_id: conference.id).present?
end
##
# Returns a user's profile picture URL.
# Partials should *not* directly call `gravatar_url`
def profile_picture(opts)
# TODO: Figure out how to align sizes?
picture.thumb.url || gravatar_url(opts)
end
def self.for_ichain_username(username, attributes)
user = find_by(username: username)