mirror of https://github.com/dani/vroom.git
Add a timestamp field to invitations
And purge those older than 2 hours
This commit is contained in:
parent
37cd041a7d
commit
c133030704
|
@ -40,6 +40,7 @@ CREATE TABLE `invitations` (
|
|||
`response` varchar(20) DEFAULT NULL,
|
||||
`message` text DEFAULT NULL,
|
||||
`processed` tinyint(1) DEFAULT '0',
|
||||
`timestamp` int(20) DEFAULT NULL,
|
||||
PRIMARY KEY (`token`)
|
||||
) DEFAULT CHARSET=utf8;
|
||||
#DROP TABLE IF EXISTS `turnusers_lt`;
|
||||
|
|
|
@ -18,5 +18,6 @@ CREATE TABLE IF NOT EXISTS `invitations` (
|
|||
`response` varchar(20) DEFAULT NULL,
|
||||
`message` text DEFAULT NULL,
|
||||
`processed` tinyint(1) DEFAULT '0',
|
||||
`timestamp` int(20) DEFAULT NULL,
|
||||
PRIMARY KEY (`token`)
|
||||
) DEFAULT CHARSET=utf8;
|
||||
|
|
|
@ -474,8 +474,8 @@ helper add_invitation => sub {
|
|||
my $data = $self->get_room($room);
|
||||
my $id = $self->get_random(50);
|
||||
return undef unless ($data);
|
||||
my $sth = eval { $self->db->prepare("INSERT INTO invitations (`id`,`from`,`token`,`email`) VALUES (?,?,?,?)") } || return undef;
|
||||
$sth->execute($data->{id},$from,$id,$email) || 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,time()) || return undef;
|
||||
return $id;
|
||||
};
|
||||
|
||||
|
@ -518,6 +518,17 @@ helper processed_invitation => sub {
|
|||
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
|
||||
any '/' => 'index';
|
||||
|
||||
|
@ -873,6 +884,10 @@ post '/action' => sub {
|
|||
if ((int (rand 100)) <= 10){
|
||||
$self->delete_rooms;
|
||||
}
|
||||
# And same for expired invitation links
|
||||
if ((int (rand 100)) <= 10){
|
||||
$self->delete_invitations;
|
||||
}
|
||||
if ($res){
|
||||
$status = 'success';
|
||||
$msg = '';
|
||||
|
|
Loading…
Reference in New Issue