Class: AuthTicket

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_ticket(secret) ⇒ Object



11
12
13
# File 'app/models/auth_ticket.rb', line 11

def self.find_ticket(secret)
  AuthTicket.find(:first, :conditions => ["secret = ? and (expires_at is null or expires_at > current_timestamp())", secret])
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/auth_ticket.rb', line 36

def expired?
  expires_at and expires_at <= Time.new
end

#generate_secretObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/auth_ticket.rb', line 15

def generate_secret
  secret = nil
  while secret.nil?
    hashseed = "#{id}_#{Time.new.to_i}_#{rand}"
    secret = Digest::SHA1.hexdigest(hashseed)
    if AuthTicket.find_by_secret(secret)
      secret = nil
    end
  end
  self.secret = secret
  return secret
end

#secretObject



28
29
30
31
32
33
34
# File 'app/models/auth_ticket.rb', line 28

def secret
  if read_attribute(:secret).nil?
    generate_secret
  else
    read_attribute(:secret)
  end
end