Module: AuthHelpers::Model::Confirmable::ClassMethods

Defined in:
lib/auth_helpers/model/confirmable.rb

Instance Method Summary collapse

Instance Method Details

#find_and_confirm(options = {}) ⇒ Object

Receives the perishable token and try to find a record to confirm the account. If it can’t find the record, returns a new record with an error set on the perishable token.


44
45
46
47
48
49
50
51
# File 'lib/auth_helpers/model/confirmable.rb', line 44

def find_and_confirm(options={})
  if confirmable = self.find_using_perishable_token(options[:perishable_token])
    confirmable.confirm!
    confirmable
  else
    AuthHelpers.new_with_perishable_token_error(self, :invalid_confirmation, options)
  end
end

#find_and_resend_confirmation_instructions(options = {}) ⇒ Object

Receives a hash with email and tries to find a record to resend the confirmation instructions. If the record can’t be found or it’s already confirmed, set the appropriate error messages and return the object.


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/auth_helpers/model/confirmable.rb', line 57

def find_and_resend_confirmation_instructions(options = {})
  confirmable = AuthHelpers.find_or_initialize_by_unless_blank(self, :email, options[:email])

  if confirmable.new_record?
    confirmable.errors.add(:email, :not_found)
  elsif confirmable.confirmed?
    confirmable.errors.add(:email, :already_confirmed)
  else
    confirmable.send_confirmation_instructions(:resend)
  end

  return confirmable
end