Add a timestamp field to invitations

And purge those older than 2 hours
master
Daniel Berteaud 11 years ago
parent 37cd041a7d
commit c133030704
  1. 1
      docs/schema.mysql
  2. 1
      docs/upgrade.mysql
  3. 19
      public/vroom.pl

@ -40,6 +40,7 @@ CREATE TABLE `invitations` (
`response` varchar(20) DEFAULT NULL, `response` varchar(20) DEFAULT NULL,
`message` text DEFAULT NULL, `message` text DEFAULT NULL,
`processed` tinyint(1) DEFAULT '0', `processed` tinyint(1) DEFAULT '0',
`timestamp` int(20) DEFAULT NULL,
PRIMARY KEY (`token`) PRIMARY KEY (`token`)
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8;
#DROP TABLE IF EXISTS `turnusers_lt`; #DROP TABLE IF EXISTS `turnusers_lt`;

@ -18,5 +18,6 @@ CREATE TABLE IF NOT EXISTS `invitations` (
`response` varchar(20) DEFAULT NULL, `response` varchar(20) DEFAULT NULL,
`message` text DEFAULT NULL, `message` text DEFAULT NULL,
`processed` tinyint(1) DEFAULT '0', `processed` tinyint(1) DEFAULT '0',
`timestamp` int(20) DEFAULT NULL,
PRIMARY KEY (`token`) PRIMARY KEY (`token`)
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8;

@ -474,8 +474,8 @@ helper add_invitation => sub {
my $data = $self->get_room($room); my $data = $self->get_room($room);
my $id = $self->get_random(50); my $id = $self->get_random(50);
return undef unless ($data); return undef unless ($data);
my $sth = eval { $self->db->prepare("INSERT INTO invitations (`id`,`from`,`token`,`email`) VALUES (?,?,?,?)") } || return undef; my $sth = eval { $self->db->prepare("INSERT INTO invitations (`id`,`from`,`token`,`email`,`timestamp`) VALUES (?,?,?,?,?)") } || return undef;
$sth->execute($data->{id},$from,$id,$email) || return undef; $sth->execute($data->{id},$from,$id,$email,time()) || return undef;
return $id; return $id;
}; };
@ -518,6 +518,17 @@ helper processed_invitation => sub {
return 1; return 1;
}; };
# Purge expired invitation links
helper delete_invitations => sub {
my $self = shift;
$self->app->log->debug('Removing expired invitations');
# Invitation older than 2 hours doesn't make much sense
my $timeout = time()-7200;
my $sth = eval { $self->db->prepare("DELETE FROM `invitations` WHERE `timestamp` < $timeout;") } || return undef;
$sth->execute() || return undef;
return 1;
};
# Route / to the index page # Route / to the index page
any '/' => 'index'; any '/' => 'index';
@ -873,6 +884,10 @@ post '/action' => sub {
if ((int (rand 100)) <= 10){ if ((int (rand 100)) <= 10){
$self->delete_rooms; $self->delete_rooms;
} }
# And same for expired invitation links
if ((int (rand 100)) <= 10){
$self->delete_invitations;
}
if ($res){ if ($res){
$status = 'success'; $status = 'success';
$msg = ''; $msg = '';

Loading…
Cancel
Save