Sha256: d7965cee9d942bb023f3919de908ecd6cb3b7c4f5617c146dbf1bc65147be362

Contents?: true

Size: 995 Bytes

Versions: 15

Compression:

Stored size: 995 Bytes

Contents

module Nyauth
  module ResetPasswordAbility
    extend ActiveSupport::Concern

    included do
      before_validation :check_reset_password_key, on: %i(reset_password edit_reset_password)
      validates :password, presence: true,
                           length: { minimum: Nyauth.configuration.password_minium },
                           on: [:create, :update_password, :reset_password]
      validates :password, confirmation: true
    end

    def reset_password(params)
      self.attributes = params
      self.save(context: :reset_password)
    end

    def request_reset_password
      self.reset_password_key = SecureRandom.hex(32)
      self.reset_password_key_expired_at = Time.current + Nyauth.configuration.reset_password_expire_limit
      save
    end

    private

    def check_reset_password_key
      if reset_password_key_expired_at.past?
        errors.add(:reset_password_key, :key_expired)
      else
        self.reset_password_key = nil
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nyauth-0.7.2 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.7.1 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.7.0 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.6.2 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.6.1 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.6.0 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.5.0 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.4.0 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.3.0 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.2.8 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.2.7 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.2.6 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.2.5 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.2.4 app/models/concerns/nyauth/reset_password_ability.rb
nyauth-0.2.3 app/models/concerns/nyauth/reset_password_ability.rb