Class: CASino::TicketGrantingTicket

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ModelConcern::BrowserInfo, ModelConcern::Ticket
Defined in:
app/models/casino/ticket_granting_ticket.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cleanup(user = nil) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/casino/ticket_granting_ticket.rb', line 14

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

#expired?Boolean

Returns:

  • (Boolean)

40
41
42
43
44
45
46
47
48
49
# File 'app/models/casino/ticket_granting_ticket.rb', line 40

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

Returns:

  • (Boolean)

32
33
34
35
36
37
38
# File 'app/models/casino/ticket_granting_ticket.rb', line 32

def same_user?(other_ticket)
  if other_ticket.nil?
    false
  else
    other_ticket.user_id == self.user_id
  end
end