Module: Devise::Models::StormpathRecoverable::ClassMethods

Defined in:
lib/devise/models/stormpath_recoverable.rb

Instance Method Summary collapse

Instance Method Details

#build_invalid_account(attributes, error) ⇒ Object



44
45
46
47
48
# File 'lib/devise/models/stormpath_recoverable.rb', line 44

def (attributes, error)
  u = self.new(attributes)
  u.errors[:base] << error.message
  u
end

#reset_password_by_token(attributes = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/devise/models/stormpath_recoverable.rb', line 32

def reset_password_by_token(attributes={})
  begin
    validate_attributes(attributes)
     = ::Stormpath::Rails::Client.verify_password_reset_token(attributes[:reset_password_token])
    .set_password attributes[:password]
    .save
    self.where(stormpath_url: .get_href).first
  rescue RuntimeError => error
    (attributes, error)
  end
end

#send_reset_password_instructions(attributes = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/devise/models/stormpath_recoverable.rb', line 21

def send_reset_password_instructions(attributes={})
  begin
    identifier = attributes[:email] || attributes[:username]
    raise RuntimeError.new "Email or username required" unless identifier
     = ::Stormpath::Rails::Client.send_password_reset_email(identifier)
    return self.where(stormpath_url: .get_href).first
  rescue RuntimeError => error
    (attributes, error)
  end
end

#validate_attributes(attributes) ⇒ Object

TODO work on better error handling and move strings to locales



51
52
53
54
55
# File 'lib/devise/models/stormpath_recoverable.rb', line 51

def validate_attributes(attributes)
  raise RuntimeError.new "Password reset token required" unless attributes[:reset_password_token]
  raise RuntimeError.new "Password should match confirmation" unless attributes[:password] == attributes[:password_confirmation]
  raise RuntimeError.new "Password required" unless attributes[:password] && !attributes[:password].empty?
end