Class: Devise::Customizers::RecoverLogin

Inherits:
Object
  • Object
show all
Extended by:
Rails3::Assist::UseMacro
Includes:
Cream::GeneratorHelper
Defined in:
lib/generators/devise/customize/helpers/recover_login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cream::GeneratorHelper

#add_logger, #debug!, included, #info!, #logit!

Constructor Details

#initialize(orm) ⇒ RecoverLogin

Returns a new instance of RecoverLogin.



13
14
15
# File 'lib/generators/devise/customize/helpers/recover_login.rb', line 13

def initialize orm
  @orm = orm
end

Instance Attribute Details

#ormObject

include Devise::UserCustomization



11
12
13
# File 'lib/generators/devise/customize/helpers/recover_login.rb', line 11

def orm
  @orm
end

Instance Method Details

#find_recoverable_codeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/devise/customize/helpers/recover_login.rb', line 35

def find_recoverable_code
  %Q{
  def self.find_recoverable_or_initialize_with_errors(required_attributes, attributes, error=:invalid)
    case_insensitive_keys.each { |k| attributes[k].try(:downcase!) }

    attributes = attributes.slice(*required_attributes)
    attributes.delete_if { |key, value| value.blank? }

    if attributes.size == required_attributes.size
     if attributes.has_key?(:login)
  login = attributes.delete(:login)
  record = find_record(login)
     else  
 record = where(attributes).first
     end  
    end  
    user_record_not_found(required_attributes) unless record
    record
  end

  #{user_record_not_found}

  def self.find_record login
    #{Devise::QueryCustomizers::FindRecord.send orm}
  end
  }
end

#reset_password_instructionsObject

should not be ORM dependent



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/devise/customize/helpers/recover_login.rb', line 22

def reset_password_instructions
  %q{
  # Attempt to find a user by it's email. If a record is found, send new
  # password instructions to it. If not user is found, returns a new user
  # with an email not found error.
  def self.send_reset_password_instructions(attributes={})
    recoverable = find_recoverable_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
    recoverable.send_reset_password_instructions if recoverable.persisted?
    recoverable
  end
  }
end

#retrieve_passwordObject



17
18
19
# File 'lib/generators/devise/customize/helpers/recover_login.rb', line 17

def retrieve_password
  reset_password_instructions << find_recoverable_code
end

#user_record_not_foundObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/generators/devise/customize/helpers/recover_login.rb', line 63

def user_record_not_found
  %q{
  # handle when the user record is not found
  # adds error messages to the record
  def self.user_record_not_found(required_attributes)
    record = new

    required_attributes.each do |key|
    value = attributes[key]
    record.send("#{key}=", value)
    record.errors.add(key, value.present? ? error : :blank)
    end  
  end  
  }
end