1
0
mirror of https://github.com/dani/vroom.git synced 2024-06-01 21:11:41 +02:00

Create API key on login, and record it in the session

This commit is contained in:
Daniel Berteaud 2014-10-21 12:41:18 +02:00
parent 64fb984264
commit a903c5d0ec

View File

@ -125,9 +125,17 @@ helper login => sub {
return 1;
}
my $login = $ENV{'REMOTE_USER'} || lc $self->get_random(256);
my $key = $self->get_random(256);
my $sth = eval {
$self->db->prepare('INSERT INTO `api_keys`
(`token`,`not_after`)
VALUES (?,DATE_ADD(CONVERT_TZ(NOW(), @@session.time_zone, \'+00:00\'), INTERVAL 24 HOUR))');
};
$sth->execute($key);
$self->session(
name => $login,
ip => $self->tx->remote_address
ip => $self->tx->remote_address,
key => $key
);
$self->app->log->info($self->session('name') . " logged in from " . $self->tx->remote_address);
return 1;