Class: CASino::TicketGrantingTicket

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/casino/ticket_granting_ticket.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cleanup(user = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/casino/ticket_granting_ticket.rb', line 9

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



27
28
29
30
31
32
33
34
35
36
# File 'app/models/casino/ticket_granting_ticket.rb', line 27

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)


46
47
48
49
50
51
52
53
54
55
# File 'app/models/casino/ticket_granting_ticket.rb', line 46

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)


38
39
40
41
42
43
44
# File 'app/models/casino/ticket_granting_ticket.rb', line 38

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