Sha256: 55aecc769a780386a44518a483233069066875b885524c9677316d1e4fe123cc

Contents?: true

Size: 855 Bytes

Versions: 3

Compression:

Stored size: 855 Bytes

Contents

module Composable
  module Pwdless
    module Form
      class Verification < Composable::Form::Command
        attribute :salt, :data, :code
        validates :data, :code, presence: true
        validates :secret, presence: true, if: -> { data? && code? }

        after_save { secret.decrement_remaining_attempts! }

        def save
          errors.add(:code, :invalid) unless secret.valid?
        end

        def invalid_code?
          !code? || errors.added?(:code, :invalid)
        end

        private

        delegate :has_expired?, :has_exceeded_attempts?, to: :secret, allow_nil: true

        def secret
          return @secret if defined?(@secret)

          @secret = Pwdless::Secret.find_by_digest(salt: salt, data: data).tap do |secret|
            secret.code = code if secret
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
composable-pwdless-0.0.12 app/services/composable/pwdless/form/verification.rb
composable-pwdless-0.0.11 app/services/composable/pwdless/form/verification.rb
composable-pwdless-0.0.10 app/services/composable/pwdless/form/verification.rb