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.27 app/models/workarea/user/password_reset.rb
workarea-core-3.5.26 app/models/workarea/user/password_reset.rb
workarea-core-3.4.45 app/models/workarea/user/password_reset.rb
workarea-core-3.5.25 app/models/workarea/user/password_reset.rb
workarea-core-3.5.23 app/models/workarea/user/password_reset.rb
workarea-core-3.4.44 app/models/workarea/user/password_reset.rb
workarea-core-3.5.22 app/models/workarea/user/password_reset.rb
workarea-core-3.4.43 app/models/workarea/user/password_reset.rb
workarea-core-3.5.21 app/models/workarea/user/password_reset.rb
workarea-core-3.4.42 app/models/workarea/user/password_reset.rb
workarea-core-3.5.20 app/models/workarea/user/password_reset.rb
workarea-core-3.4.41 app/models/workarea/user/password_reset.rb
workarea-core-3.5.19 app/models/workarea/user/password_reset.rb
workarea-core-3.4.40 app/models/workarea/user/password_reset.rb
workarea-core-3.5.18 app/models/workarea/user/password_reset.rb
workarea-core-3.4.39 app/models/workarea/user/password_reset.rb
workarea-core-3.5.17 app/models/workarea/user/password_reset.rb
workarea-core-3.4.38 app/models/workarea/user/password_reset.rb
workarea-core-3.5.16 app/models/workarea/user/password_reset.rb
workarea-core-3.4.37 app/models/workarea/user/password_reset.rb