2024-12-31 14:20:22 +08:00
|
|
|
class User < ApplicationRecord
|
|
|
|
# before_save { self.email = email.downcase }
|
|
|
|
before_save { email.downcase! }
|
|
|
|
validates :name, presence: true, length: { maximum: 50 }
|
|
|
|
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
|
|
|
|
validates :email, presence: true, length: { maximum: 255 },
|
|
|
|
format: { with: VALID_EMAIL_REGEX },
|
|
|
|
uniqueness: true
|
|
|
|
has_secure_password
|
|
|
|
validates :password, presence: true, length: { minimum: 6 }
|
2025-01-02 11:59:27 +08:00
|
|
|
|
|
|
|
def User.digest(string)
|
|
|
|
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
|
|
|
|
BCrypt::Engine.cost
|
|
|
|
BCrypt::Password.create(string, cost: cost)
|
|
|
|
end
|
2024-12-31 14:20:22 +08:00
|
|
|
end
|