Class: CASino::TicketGrantingTicket

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
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



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

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_infoObject



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

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

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
# File 'app/models/casino/ticket_granting_ticket.rb', line 50

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)


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

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