Sha256: 9928c2be5aa470434425d48f9cce92f1ef51bd78ce7f32e868c6c9473a0f5ddc

Contents?: true

Size: 899 Bytes

Versions: 33

Compression:

Stored size: 899 Bytes

Contents

module Workarea
  class User
    class PasswordReset
      include ApplicationDocument
      include UrlToken

      belongs_to :user, class_name: 'Workarea::User', index: true

      index(
        { created_at: 1 },
        { expire_after_seconds: Workarea.config.password_reset_timeout }
      )

      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

      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
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/models/workarea/user/password_reset.rb
workarea-core-3.4.36 app/models/workarea/user/password_reset.rb
workarea-core-3.5.14 app/models/workarea/user/password_reset.rb
workarea-core-3.4.35 app/models/workarea/user/password_reset.rb
workarea-core-3.5.13 app/models/workarea/user/password_reset.rb
workarea-core-3.4.34 app/models/workarea/user/password_reset.rb
workarea-core-3.5.12 app/models/workarea/user/password_reset.rb
workarea-core-3.4.33 app/models/workarea/user/password_reset.rb
workarea-core-3.5.11 app/models/workarea/user/password_reset.rb
workarea-core-3.5.10 app/models/workarea/user/password_reset.rb
workarea-core-3.4.32 app/models/workarea/user/password_reset.rb
workarea-core-3.5.9 app/models/workarea/user/password_reset.rb
workarea-core-3.4.31 app/models/workarea/user/password_reset.rb