Module: Card::Set::Right::Token
- Extended by:
- Card::Set
- Includes:
- All::Permissions::Accounts
- Defined in:
- tmpsets/set/mod025-account/right/token.rb
Overview
Set: All "+Token" cards
Constant Summary collapse
- DURATIONS =
"second|minute|hour|day|week|month|year".freeze
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #history? ⇒ Boolean
- #permanent? ⇒ Boolean
- #term ⇒ Object
- #term_from_string(string) ⇒ Object
- #used! ⇒ Object
- #validate!(token) ⇒ Object
Methods included from I18nScope
Methods included from Loader
#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set
Methods included from Helpers
#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore
Methods included from AdvancedApi
#attachment, #ensure_set, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Basket
#abstract_basket, #add_to_basket, #basket, #unshift_basket
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Methods included from All::Permissions::Accounts
Class Method Details
.source_location ⇒ Object
7 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/account/set/right/token.rb"; end |
Instance Method Details
#expired? ⇒ Boolean
32 33 34 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 32 def expired? !permanent? && updated_at <= term.ago end |
#history? ⇒ Boolean
14 15 16 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 14 def history? false end |
#permanent? ⇒ Boolean
36 37 38 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 36 def permanent? term == "permanent" end |
#term ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 45 def term @term ||= if expiration.present? term_from_string expiration else Card.config.token_expiry end end |
#term_from_string(string) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 54 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::Open::Error, tr(:exception_bad_expiration, example: '2 days') unless unit number.to_i.send unit end |
#used! ⇒ Object
40 41 42 43 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 40 def used! # immediate deletion was causing problems. commenting for now # Auth.as_bot { delete! } unless permanent? end |
#validate!(token) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'tmpsets/set/mod025-account/right/token.rb', line 22 def validate! token error = case when !real? then [:token_not_found, tr(:error_token_not_found)] when expired? then [:token_expired, tr(:error_token_expired)] when content != token then [:incorrect_token, tr(:error_incorrect_token)] end errors.add *error if error end |