Sha256: 2f040e6e6c26c75d5ef32e011a3a3dc35e10af83f8d5add80feac95349f78d09
Contents?: true
Size: 1.08 KB
Versions: 7
Compression:
Stored size: 1.08 KB
Contents
include All::Permissions::Accounts DURATIONS = "second|minute|hour|day|week|month|year".freeze card_accessor :expiration view :raw do "Private data" end def validate! token error = case when !real? then [:token_not_found, "no token found"] when expired? then [:token_expired, "expired token"] when content != token then [:incorrect_token, "token mismatch"] end errors.add *error if error end def expired? !permanent? && updated_at <= term.ago end def permanent? term == "permanent" end def used! # immediate deletion was causing problems. commenting for now # Auth.as_bot { delete! } unless permanent? end def term @term ||= if expiration.present? term_from_string expiration else Card.config.token_expiry end end def term_from_string string string.strip! return "permanent" if string == "none" re_match = /^(\d+)[\.\s]*(#{DURATIONS})s?$/.match(string) number, unit = re_match.captures if re_match raise Card::Error::Oops, "illegal expiration value (eg '2 days')" unless unit number.to_i.send unit end
Version data entries
7 entries across 7 versions & 1 rubygems