24 lines
577 B
Ruby
24 lines
577 B
Ruby
class AdminUser < ApplicationRecord
|
|
has_secure_password
|
|
|
|
validates :email, presence: true, uniqueness: { case_sensitive: false }, format: { with: URI::MailTo::EMAIL_REGEXP }
|
|
validates :name, presence: true
|
|
validates :password, length: { minimum: 8 }, if: -> { password.present? }
|
|
|
|
before_validation :normalize_email
|
|
|
|
def update_last_login!
|
|
update!(last_login_at: Time.current)
|
|
end
|
|
|
|
def ntfy_configured?
|
|
ntfy_enabled? && ntfy_topic.present? && ntfy_token.present?
|
|
end
|
|
|
|
private
|
|
|
|
def normalize_email
|
|
self.email = email&.downcase&.strip
|
|
end
|
|
end
|