This commit is contained in:
Albert Yi
2018-05-15 14:19:45 -07:00
parent c36efc1f62
commit 8bb890e4d0
4 changed files with 17 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
class UserPasswordResetNonce < ApplicationRecord
validates_presence_of :email, :key
has_secure_token :key
validates_presence_of :email
validate :validate_existence_of_email
before_validation :initialize_key, :on => :create
after_create :deliver_notice
def self.prune!
@@ -12,10 +12,6 @@ class UserPasswordResetNonce < ApplicationRecord
Maintenance::User::PasswordResetMailer.reset_request(user, self).deliver_now
end
def initialize_key
self.key = SecureRandom.hex(16)
end
def validate_existence_of_email
if !User.with_email(email).exists?
errors[:email] << "is invalid"