eBooru/app/models/user_password_reset_nonce.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

28 lines
594 B
Ruby

# frozen_string_literal: true
class UserPasswordResetNonce < ApplicationRecord
has_secure_token :key
after_create :deliver_notice
belongs_to :user
def self.prune!
where("created_at < ?", 2.days.ago).destroy_all
end
def deliver_notice
if user.email.present?
Maintenance::User::PasswordResetMailer.reset_request(user, self).deliver_now
end
end
def reset_user!(pass, confirm)
return false if !ActiveSupport::SecurityUtils.secure_compare(pass, confirm)
user.upgrade_password(pass)
true
end
def expired?
created_at < 24.hours.ago
end
end