create basic backend with login
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
class User < ApplicationRecord
|
||||
has_secure_password validations: false
|
||||
|
||||
has_many :sessions, dependent: :destroy
|
||||
has_one_attached :avatar
|
||||
|
||||
normalizes :nickname, with: ->(n) { n.strip }
|
||||
|
||||
validates :nickname, presence: true, uniqueness: { case_sensitive: false }, length: { minimum: 3, maximum: 24 }
|
||||
validates :password, presence: true, length: { minimum: 6 }, if: -> { new_record? || password_digest_changed? }
|
||||
validate :avatar_content_type, if: -> { avatar.attached? }
|
||||
|
||||
private
|
||||
def avatar_content_type
|
||||
unless avatar.blob.content_type.in?(%w[image/png image/jpeg image/gif image/webp])
|
||||
errors.add(:avatar, "must be a PNG, JPEG, GIF or WebP image")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user