mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
38 lines
1.1 KiB
Ruby
38 lines
1.1 KiB
Ruby
module Devise
|
|
module Perishable
|
|
|
|
def self.included(base)
|
|
base.class_eval do
|
|
extend ClassMethods
|
|
|
|
before_create :reset_perishable_token
|
|
end
|
|
end
|
|
|
|
# Generates a new random token for confirmation, based on actual Time and salt
|
|
#
|
|
def reset_perishable_token
|
|
self.perishable_token = secure_digest(Time.now.utc, random_string, password)
|
|
end
|
|
|
|
# Resets the perishable token with and save the record without validating
|
|
#
|
|
def reset_perishable_token!
|
|
reset_perishable_token and save(false)
|
|
end
|
|
|
|
module ClassMethods
|
|
|
|
# Attempt to find a user by and incoming perishable_token. If no user is
|
|
# found, initialize a new one and adds an :invalid error to perishable_token
|
|
#
|
|
def find_or_initialize_with_error_by_perishable_token(perishable_token)
|
|
perishable = find_or_initialize_by_perishable_token(perishable_token)
|
|
if perishable.new_record?
|
|
perishable.errors.add(:perishable_token, :invalid, :default => "invalid confirmation")
|
|
end
|
|
perishable
|
|
end
|
|
end
|
|
end
|
|
end
|