From a903c5d0ecb46dd4f7da435fc59c255ae1330816 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 21 Oct 2014 12:41:18 +0200 Subject: [PATCH] Create API key on login, and record it in the session --- vroom.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vroom.pl b/vroom.pl index 1d6594f..36b2156 100755 --- a/vroom.pl +++ b/vroom.pl @@ -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;