Class: Accountly::PasswordForm
- Inherits:
-
Object
- Object
- Accountly::PasswordForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/accountly/password_form.rb
Instance Attribute Summary collapse
-
#new_password ⇒ Object
Returns the value of attribute new_password.
-
#original_password ⇒ Object
Returns the value of attribute original_password.
Instance Method Summary collapse
-
#initialize(user) ⇒ PasswordForm
constructor
A new instance of PasswordForm.
- #submit(params) ⇒ Object
- #verify_original_password ⇒ Object
Constructor Details
#initialize(user) ⇒ PasswordForm
Returns a new instance of PasswordForm.
14 15 16 |
# File 'app/forms/accountly/password_form.rb', line 14 def initialize(user) @user = user end |
Instance Attribute Details
#new_password ⇒ Object
Returns the value of attribute new_password.
5 6 7 |
# File 'app/forms/accountly/password_form.rb', line 5 def new_password @new_password end |
#original_password ⇒ Object
Returns the value of attribute original_password.
5 6 7 |
# File 'app/forms/accountly/password_form.rb', line 5 def original_password @original_password end |
Instance Method Details
#submit(params) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/forms/accountly/password_form.rb', line 18 def submit(params) self.original_password = params[:original_password] self.new_password = params[:new_password] self.new_password_confirmation = params[:new_password_confirmation] if valid? @user.password = new_password @user.password_confirmation = new_password_confirmation @user.save! true else false end end |
#verify_original_password ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/forms/accountly/password_form.rb', line 33 def verify_original_password if @user.authenticate(original_password) true else errors.add :original_password, I18n.t('activemodel.errors.models.accountly/password_form.attributes.original_password.invalid') false end end |