lib/clarion/authn.rb in clarion-0.2.1 vs lib/clarion/authn.rb in clarion-0.3.0

- old
+ new

@@ -2,18 +2,23 @@ require 'securerandom' require 'clarion/key' module Clarion class Authn - STATUSES = %i(open verified) + STATUSES = %i(open cancelled verified expired) class << self def make(**kwargs) kwargs.delete(:id) + kwargs.delete(:created_at) + kwargs.delete(:status) + kwargs.delete(:verified_at) + kwargs.delete(:verified_key) new( id: random_id, created_at: Time.now, + status: :open, **kwargs, ) end def random_id @@ -34,10 +39,12 @@ @created_at = Time.xmlschema(@created_at) if @created_at && @created_at.is_a?(String) @expires_at = Time.xmlschema(@expires_at) if @expires_at && @expires_at.is_a?(String) @verified_at = Time.xmlschema(@verified_at) if @verified_at && @verified_at.is_a?(String) + @status = :expired if expired? + raise ArgumentError, ":status not valid" unless STATUSES.include?(@status) end attr_reader :id, :name, :comment attr_reader :keys @@ -56,10 +63,18 @@ def verified? status == :verified end + def cancelled? + status == :cancelled + end + + def closed? + !open? || expired? + end + def key_for_handle(handle) keys.find { |_| _.handle == handle } end def verify(key, verified_at: Time.now) @@ -67,9 +82,14 @@ return false end @verified_at = verified_at @verified_key = key @status = :verified + true + end + + def cancel! + @status = :cancelled true end def to_h(all=false) {