Class: Workarea::User::PasswordReset

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument, Workarea::UrlToken
Defined in:
app/models/workarea/user/password_reset.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.setup!(email) ⇒ Object



14
15
16
17
18
19
20
# File 'app/models/workarea/user/password_reset.rb', line 14

def self.setup!(email)
  user = User.find_by_email(email)
  return nil unless user

  where(user_id: user.id).destroy_all
  create!(user: user)
end

Instance Method Details

#complete(new_password) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/workarea/user/password_reset.rb', line 22

def complete(new_password)
  if new_password.blank?
    errors.add(:password, I18n.t('errors.messages.blank'))
    return false
  end

  if user.update_attributes(password: new_password)
    destroy
  else
    user.errors.each do |attribute, error|
      errors.add(attribute, error)
    end
    false
  end
end