Some fixes in API Key and session handling

master
Daniel Berteaud 9 years ago
parent 1368baec84
commit ae2d160f9e
  1. 11
      vroom.pl

@ -156,7 +156,7 @@ helper get_name => sub {
# And a new API key # And a new API key
helper login => sub { helper login => sub {
my $self = shift; my $self = shift;
if ($self->session('id')){ if ($self->session('id') && $self->session('id') ne ''){
return 1; return 1;
} }
my $id = $self->get_random(256); my $id = $self->get_random(256);
@ -168,8 +168,8 @@ helper login => sub {
}; };
$sth->execute($key); $sth->execute($key);
$self->session( $self->session(
id => $id, id => $id,
key => $key key => $key
); );
$self->app->log->info($self->get_name . " logged in from " . $self->tx->remote_address); $self->app->log->info($self->get_name . " logged in from " . $self->tx->remote_address);
return 1; return 1;
@ -188,6 +188,11 @@ helper logout => sub {
$peers->{$self->session('peer_id')}->{socket}){ $peers->{$self->session('peer_id')}->{socket}){
$peers->{$self->session('peer_id')}->{socket}->finish; $peers->{$self->session('peer_id')}->{socket}->finish;
} }
my $sth = eval {
$self->db->prepare('DELETE FROM `api_keys`
WHERE `token`=?');
};
$sth->execute($self->session('key'));
$self->app->log->info($self->get_name . " logged out"); $self->app->log->info($self->get_name . " logged out");
$self->session( expires => 1 ); $self->session( expires => 1 );
return 1; return 1;

Loading…
Cancel
Save