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

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.setup!(email) ⇒ Object



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

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

Instance Method Details

#complete(new_password) ⇒ Object



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

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