Module: Card::Set::Right::Token
- Extended by:
- Card::Set
- Includes:
- All::Permissions::Accounts
- Defined in:
- tmpsets/set/mod017-account/right/token.rb
Constant Summary collapse
- DURATIONS =
"second|minute|hour|day|week|month|year".freeze
Constants included from Format
Constants included from Event::DelayedEvent
Event::DelayedEvent::DELAY_STAGES
Instance Method Summary collapse
- #expired? ⇒ 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
Methods included from AdvancedApi
#attachment, #ensure_set, #stage_method
Methods included from Format
#all_set_format_mod!, #define_on_format, #format, #register_set_format, #view
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Basket
#abstract_basket, #add_to_basket, #basket
Methods included from Trait
#card_accessor, #card_reader, #card_writer
Methods included from Event
Methods included from All::Permissions::Accounts
Instance Method Details
#expired? ⇒ Boolean
24 25 26 |
# File 'tmpsets/set/mod017-account/right/token.rb', line 24 def expired? !permanent? && updated_at <= term.ago end |
#permanent? ⇒ Boolean
28 29 30 |
# File 'tmpsets/set/mod017-account/right/token.rb', line 28 def permanent? term == "permanent" end |
#term ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'tmpsets/set/mod017-account/right/token.rb', line 36 def term @term ||= if expiration.present? term_from_string expiration else Card.config.token_expiry end end |
#term_from_string(string) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'tmpsets/set/mod017-account/right/token.rb', line 45 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 |
#used! ⇒ Object
32 33 34 |
# File 'tmpsets/set/mod017-account/right/token.rb', line 32 def used! Auth.as_bot { delete! } unless permanent? end |
#validate!(token) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'tmpsets/set/mod017-account/right/token.rb', line 14 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 |