Sha256: 554ac3a9e7d0ce489d7cb0962c8cc1939031566e95eb53ce270cf3ef8f097f34

Contents?: true

Size: 729 Bytes

Versions: 15

Compression:

Stored size: 729 Bytes

Contents

module Nyauth
  module Confirmable
    extend ActiveSupport::Concern

    included do
      before_validation :check_confirmation_key, on: :confirm
    end

    def confirm
      self.confirmed_at = Time.current
      save(context: :confirm)
    end

    def confirmed?
      self.confirmed_at.present?
    end

    def request_confirmation
      self.confirmation_key = SecureRandom.hex(32)
      self.confirmation_key_expired_at = Time.current + Nyauth.configuration.confirmation_expire_limit
      save
    end

    private

    def check_confirmation_key
      if confirmation_key_expired_at.past?
        errors.add(:confirmation_key, :key_expired)
      else
        self.confirmation_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/confirmable.rb
nyauth-0.7.1 app/models/concerns/nyauth/confirmable.rb
nyauth-0.7.0 app/models/concerns/nyauth/confirmable.rb
nyauth-0.6.2 app/models/concerns/nyauth/confirmable.rb
nyauth-0.6.1 app/models/concerns/nyauth/confirmable.rb
nyauth-0.6.0 app/models/concerns/nyauth/confirmable.rb
nyauth-0.5.0 app/models/concerns/nyauth/confirmable.rb
nyauth-0.4.0 app/models/concerns/nyauth/confirmable.rb
nyauth-0.3.0 app/models/concerns/nyauth/confirmable.rb
nyauth-0.2.8 app/models/concerns/nyauth/confirmable.rb
nyauth-0.2.7 app/models/concerns/nyauth/confirmable.rb
nyauth-0.2.6 app/models/concerns/nyauth/confirmable.rb
nyauth-0.2.5 app/models/concerns/nyauth/confirmable.rb
nyauth-0.2.4 app/models/concerns/nyauth/confirmable.rb
nyauth-0.2.3 app/models/concerns/nyauth/confirmable.rb