Module: Revise::Models::Recoverable

Extended by:
ActiveSupport::Concern
Defined in:
lib/revise/models/recoverable.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

MAILERS =
['Recoverable']
HELPERS =
[]
CONTROLLERS =
['Recovery']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.required_fields(klass) ⇒ Object



10
11
12
# File 'lib/revise/models/recoverable.rb', line 10

def self.required_fields(klass)
  [:reset_password_sent_at, :reset_password_token, :email]
end

Instance Method Details

#generate_reset_password_tokenObject

Generates a new random token for reset password



36
37
38
39
40
# File 'lib/revise/models/recoverable.rb', line 36

def generate_reset_password_token
  self.reset_password_token   = self.class.reset_password_token
  self.reset_password_sent_at = Time.now.utc
  self.reset_password_token
end

#generate_reset_password_token!Object

Resets the reset password token with and save the record without validating



44
45
46
# File 'lib/revise/models/recoverable.rb', line 44

def generate_reset_password_token!
  generate_reset_password_token && save(:validate => false)
end

#reset_password!(new_password, new_password_confirmation) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/revise/models/recoverable.rb', line 14

def reset_password!(new_password, new_password_confirmation)
  self.password              = new_password
  self.password_confirmation = new_password_confirmation

  if valid?
    clear_reset_password_token
    after_password_reset
  end

  save
end

#reset_password_period_valid?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/revise/models/recoverable.rb', line 31

def reset_password_period_valid?
  reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago
end

#send_reset_password_instructionsObject



26
27
28
29
# File 'lib/revise/models/recoverable.rb', line 26

def send_reset_password_instructions
  generate_reset_password_token! if should_generate_reset_token?
  send_revise_notification(:recoverable, :reset_password_instructions, self.name, self.email, self.reset_password_token)
end