Module: Devise::Models::StormpathRecoverable::ClassMethods
- Defined in:
- lib/devise/models/stormpath_recoverable.rb
Instance Method Summary collapse
- #build_invalid_account(attributes, error) ⇒ Object
- #reset_password_by_token(attributes = {}) ⇒ Object
- #send_reset_password_instructions(attributes = {}) ⇒ Object
-
#validate_attributes(attributes) ⇒ Object
TODO work on better error handling and move strings to locales.
Instance Method Details
#build_invalid_account(attributes, error) ⇒ Object
44 45 46 47 48 |
# File 'lib/devise/models/stormpath_recoverable.rb', line 44 def build_invalid_account(attributes, error) u = self.new(attributes) u.errors[:base] << error. 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) account = ::Stormpath::Rails::Client.verify_password_reset_token(attributes[:reset_password_token]) account.set_password attributes[:password] account.save self.where(stormpath_url: account.get_href).first rescue RuntimeError => error build_invalid_account(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 account = ::Stormpath::Rails::Client.send_password_reset_email(identifier) return self.where(stormpath_url: account.get_href).first rescue RuntimeError => error build_invalid_account(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 |