[7908f1]: lib / WineTestBot / CGI / Sessions.pm  Maximize  Restore  History

Download this file

128 lines (99 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Web session handling
#
# Copyright 2009 Ge van Geldorp
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
use strict;
=head1 NAME
WineTestBot::CGI::Sessions - Session collection
=cut
package WineTestBot::CGI::Session;
use WineTestBot::Utils;
use WineTestBot::WineTestBotObjects;
require Exporter;
use vars qw(@ISA @EXPORT);
@ISA = qw(WineTestBot::WineTestBotItem Exporter);
sub InitializeNew
{
my $self = shift;
$self->SUPER::InitializeNew(@_);
$self->Permanent(!1);
}
package WineTestBot::CGI::Sessions;
use CGI::Cookie;
use ObjectModel::BasicPropertyDescriptor;
use ObjectModel::ItemrefPropertyDescriptor;
use WineTestBot::Config;
use WineTestBot::Users;
use WineTestBot::Utils;
use WineTestBot::WineTestBotObjects;
use vars qw(@ISA @EXPORT @PropertyDescriptors);
require Exporter;
@ISA = qw(WineTestBot::WineTestBotCollection Exporter);
@EXPORT = qw(&CreateSessions &NewSession);
BEGIN
{
$PropertyDescriptors[0] =
CreateBasicPropertyDescriptor("Id", "Session id", 1, 1, "A", 32);
$PropertyDescriptors[1] =
CreateItemrefPropertyDescriptor("User", "User", !1, 1, \&CreateUsers, ["UserName"]);
$PropertyDescriptors[2] =
CreateBasicPropertyDescriptor("Permanent", "Permanent session", !1, 1, "B", 1);
}
sub CreateItem
{
my $self = shift;
return WineTestBot::CGI::Session->new($self);
}
sub DeleteNonPermanentSessions
{
my $self = shift;
my $User = $_[0];
$self->AddFilter("User", [$User]);
$self->AddFilter("Permanent", [!1]);
foreach my $Key (@{$self->GetKeys()})
{
$self->DeleteItem($self->GetItem($Key));
}
}
sub NewSession
{
my $self = shift;
my ($User, $Permanent) = @_;
CreateSessions()->DeleteNonPermanentSessions($User);
my $Session = $self->Add();
my $Existing = $Session;
my $Id;
while (defined($Existing))
{
$Id = "";
foreach my $i (1..8)
{
$Id .= sprintf("%lx", int(rand(2 ** 16)));
}
$Existing = $self->GetItem($Id);
}
$Session->Id($Id);
$Session->User($User);
$Session->Permanent($Permanent);
my ($ErrKey, $ErrProperty, $ErrMessage) = $self->Save();
return ($ErrMessage, $Session);
}
sub CreateSessions
{
return WineTestBot::CGI::Sessions->new("Sessions", "Sessions", "Session",
\@PropertyDescriptors);
}
1;