Class: CASino::TicketGrantingTicket
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CASino::TicketGrantingTicket
- Defined in:
- app/models/casino/ticket_granting_ticket.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.cleanup(user = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/casino/ticket_granting_ticket.rb', line 10 def self.cleanup(user = nil) if user.nil? base = self else base = user.ticket_granting_tickets end tgts = base.where([ '(created_at < ? AND awaiting_two_factor_authentication = ?) OR (created_at < ? AND long_term = ?) OR created_at < ?', CASino.config.two_factor_authenticator[:timeout].seconds.ago, true, CASino.config.ticket_granting_ticket[:lifetime].seconds.ago, false, CASino.config.ticket_granting_ticket[:lifetime_long_term].seconds.ago ]) CASino::ServiceTicket.where(ticket_granting_ticket_id: tgts).destroy_all tgts.destroy_all end |
Instance Method Details
#browser_info ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/casino/ticket_granting_ticket.rb', line 28 def browser_info unless self.user_agent.blank? user_agent = UserAgent.parse(self.user_agent) if user_agent.platform.nil? "#{user_agent.browser}" else "#{user_agent.browser} (#{user_agent.platform})" end end end |
#expired? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/casino/ticket_granting_ticket.rb', line 47 def expired? if awaiting_two_factor_authentication? lifetime = CASino.config.two_factor_authenticator[:timeout] elsif long_term? lifetime = CASino.config.ticket_granting_ticket[:lifetime_long_term] else lifetime = CASino.config.ticket_granting_ticket[:lifetime] end (Time.now - (self.created_at || Time.now)) > lifetime end |
#same_user?(other_ticket) ⇒ Boolean
39 40 41 42 43 44 45 |
# File 'app/models/casino/ticket_granting_ticket.rb', line 39 def same_user?(other_ticket) if other_ticket.nil? false else other_ticket.user_id == self.user_id end end |