Class: LoginTicket

Inherits:
Object
  • Object
show all
Defined in:
lib/login_ticket.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create!(store) ⇒ Object



10
11
12
13
14
# File 'lib/login_ticket.rb', line 10

def create!(store)
  lt =  self.new
  lt.save!(store)
  lt
end

.expire_timeObject



16
17
18
# File 'lib/login_ticket.rb', line 16

def expire_time
  300
end

.validate!(ticket, store) ⇒ Object



3
4
5
6
7
8
# File 'lib/login_ticket.rb', line 3

def validate!(ticket, store)
  if store.exists ticket
    store.del ticket
    new
  end
end

Instance Method Details

#remaining_time(store) ⇒ Object



25
26
27
# File 'lib/login_ticket.rb', line 25

def remaining_time(store)
  store.ttl ticket
end

#save!(store) ⇒ Object



30
31
32
33
# File 'lib/login_ticket.rb', line 30

def save!(store)
  store[ticket] = 1
  store.expire ticket, self.class.expire_time
end

#ticketObject



21
22
23
# File 'lib/login_ticket.rb', line 21

def ticket
  @ticket ||= "LT-#{rand(100000000000000000)}".to_s
end