Class: Accountly::UsernameForm
- Inherits:
-
Object
- Object
- Accountly::UsernameForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/accountly/username_form.rb
Instance Attribute Summary collapse
-
#new_username ⇒ Object
Returns the value of attribute new_username.
-
#new_username_confirmation ⇒ Object
Returns the value of attribute new_username_confirmation.
-
#original_password ⇒ Object
Returns the value of attribute original_password.
Instance Method Summary collapse
-
#initialize(user) ⇒ UsernameForm
constructor
A new instance of UsernameForm.
- #submit(params) ⇒ Object
- #verify_original_password ⇒ Object
- #verify_unique_username ⇒ Object
Constructor Details
#initialize(user) ⇒ UsernameForm
Returns a new instance of UsernameForm.
16 17 18 |
# File 'app/forms/accountly/username_form.rb', line 16 def initialize(user) @user = user end |
Instance Attribute Details
#new_username ⇒ Object
Returns the value of attribute new_username.
5 6 7 |
# File 'app/forms/accountly/username_form.rb', line 5 def new_username @new_username end |
#new_username_confirmation ⇒ Object
Returns the value of attribute new_username_confirmation.
5 6 7 |
# File 'app/forms/accountly/username_form.rb', line 5 def new_username_confirmation @new_username_confirmation end |
#original_password ⇒ Object
Returns the value of attribute original_password.
5 6 7 |
# File 'app/forms/accountly/username_form.rb', line 5 def original_password @original_password end |
Instance Method Details
#submit(params) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/forms/accountly/username_form.rb', line 20 def submit(params) self.original_password = params[:original_password] self.new_username = params[:new_username] self.new_username_confirmation = params[:new_username_confirmation] if valid? @user.username = new_username @user.save! true else false end end |
#verify_original_password ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/forms/accountly/username_form.rb', line 40 def verify_original_password if @user.authenticate(original_password) true else errors.add :original_password, I18n.t('activemodel.errors.models.accountly/username_form.attributes.original_password.invalid') false end end |
#verify_unique_username ⇒ Object
34 35 36 37 38 |
# File 'app/forms/accountly/username_form.rb', line 34 def verify_unique_username unless @user.confirmed_duplicate_username(self.new_username) errors.add :new_username, I18n.t('activemodel.errors.models.accountly/username_form.attributes.new_username.duplicate') end end |