« blib/lib/Keystone/Resolver/DB/ServiceTypeRule.pm
↑ Summary
blib/lib/Keystone/Resolver/DB/Site.pm »
| 1 | # $Id: Session.pm,v 1.4 2007-05-29 17:16:31 mike Exp $ | ||
| 2 | |||
| 3 | package Keystone::Resolver::DB::Session; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use Keystone::Resolver::DB::Object; | ||
| 8 | |||
| 9 | use vars qw(@ISA); | ||
| 10 | @ISA = qw(Keystone::Resolver::DB::Object); | ||
| 11 | |||
| 12 | |||
| 13 | sub table { "session" } | ||
| 14 | sub fields { (id => undef, | ||
| 15 | site_id => undef, | ||
| 16 | cookie => undef, | ||
| 17 | user_id => undef, | ||
| 18 | dest => undef, | ||
| 19 | query => undef, | ||
| 20 | ) } | ||
| 21 | |||
| 22 | # Generate a suitable opaque session key to use included as the | ||
| 23 | # session-cookie's value. We could include information in this key, | ||
| 24 | # such as an encrypted version of the IP address that the session was | ||
| 25 | # created for -- then we'd be able to reject cookies submitted from | ||
| 26 | # the wrong machine. But for now, we just generate randomly. | ||
| 27 | # | ||
| 28 | sub create { | ||
| 29 | my $class = shift(); | ||
| 30 | |||
| 31 | my $chars = join("", "A".."Z", "a".."z", "0".."9", "+", "/"); | ||
| 32 | my $cookie = ""; | ||
| 33 | foreach my $i (1..12) { | ||
| 34 | $cookie .= substr($chars, int(rand()*64), 1); | ||
| 35 | } | ||
| 36 | |||
| 37 | return $class->SUPER::create(@_, cookie => $cookie); | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | 1; |