Remove a few useless initializations

master
Daniel Berteaud 10 years ago
parent 2653bd6686
commit 8b0dfdccce
  1. 64
      vroom.pl

@ -89,21 +89,17 @@ plugin mail => {
helper valid_room_name => sub { helper valid_room_name => sub {
my $self = shift; my $self = shift;
my ($name) = @_; my ($name) = @_;
my $ret = {status => undef, msg => undef}; my $ret = {};
# A few names are reserved # A few names are reserved
my @reserved = qw(about help feedback feedback_thanks goodbye admin create localize action my @reserved = qw(about help feedback feedback_thanks goodbye admin create localize action
missing dies password kicked invitation js css img fonts snd); missing dies password kicked invitation js css img fonts snd);
if ($name !~ m/^[\w\-]{1,49}$/){ if ($name !~ m/^[\w\-]{1,49}$/){
$ret->{msg} = 'ERROR_NAME_INVALID'; return {msg => 'ERROR_NAME_INVALID'};
} }
elsif (grep { $name eq $_ } @reserved){ elsif (grep { $name eq $_ } @reserved){
$ret->{msg} = 'ERROR_NAME_RESERVED'; return {msg => 'ERROR_NAME_RESERVED'};
} }
else{ return {status => 1};
$ret->{status} = 1;
$ret->{msg} = 'OK'
}
return $ret;
}; };
# Check id arg is a valid ID number # Check id arg is a valid ID number
@ -123,14 +119,9 @@ helper valid_id => sub {
# Create a cookie based session # Create a cookie based session
helper login => sub { helper login => sub {
my $self = shift; my $self = shift;
my $ret = { my $ret = {};
status => undef,
msg => undef
};
if ($self->session('name')){ if ($self->session('name')){
$ret->{status} = 1; return {status => 1};
$ret->{msg} = 'ALREADY_LOGGED';
return $ret;
} }
my $login = $ENV{'REMOTE_USER'} || lc $self->get_random(256); my $login = $ENV{'REMOTE_USER'} || lc $self->get_random(256);
$self->session( $self->session(
@ -138,28 +129,21 @@ helper login => sub {
ip => $self->tx->remote_address ip => $self->tx->remote_address
); );
$self->app->log->info($self->session('name') . " logged in from " . $self->tx->remote_address); $self->app->log->info($self->session('name') . " logged in from " . $self->tx->remote_address);
$ret->{status} = 1; return {status => 1};
$ret->{msg} = 'LOGIN_SUCCESS';
return $ret;
}; };
# Expire the cookie # Expire the cookie
helper logout => sub { helper logout => sub {
my $self = shift; my $self = shift;
my ($room) = @_; my ($room) = @_;
my $ret = { my $ret = {};
status => undef,
msg => undef
};
# Logout from etherpad # Logout from etherpad
if ($ec && $self->session($room) && $self->session($room)->{etherpadSessionId}){ if ($ec && $self->session($room) && $self->session($room)->{etherpadSessionId}){
$ec->delete_session($self->session($room)->{etherpadSessionId}); $ec->delete_session($self->session($room)->{etherpadSessionId});
} }
$self->session( expires => 1 ); $self->session( expires => 1 );
$self->app->log->info($self->session('name') . " logged out"); $self->app->log->info($self->session('name') . " logged out");
$ret->{status} = 1; return {status => 1};
$ret->{msg} = 'LOGOUT_SUCCESS';
return $ret;
}; };
# Create a new room in the DB # Create a new room in the DB
@ -167,7 +151,7 @@ helper logout => sub {
helper create_room => sub { helper create_room => sub {
my $self = shift; my $self = shift;
my ($name,$owner) = @_; my ($name,$owner) = @_;
my $res = {status => undef, msg => undef}; my $res = {};
# Convert room names to lowercase # Convert room names to lowercase
if ($name ne lc $name){ if ($name ne lc $name){
$name = lc $name; $name = lc $name;
@ -177,8 +161,8 @@ helper create_room => sub {
if (!$res->{status}){ if (!$res->{status}){
return $res; return $res;
} }
elsif ($self->get_room_by_name($name)->{data}){ $res = $self->get_room_by_name($name);
$res->{msg} = 'ERROR_NAME_CONFLICT'; if ($res->{data}){
return $res; return $res;
} }
my $sth = eval { my $sth = eval {
@ -197,8 +181,7 @@ helper create_room => sub {
?)'); ?)');
}; };
if ($@){ if ($@){
$res->{msg} = $@; return {msg => $@};
return $res;
} }
$sth->execute( $sth->execute(
$name, $name,
@ -207,17 +190,14 @@ helper create_room => sub {
$config->{'turn.realm'} $config->{'turn.realm'}
); );
if ($sth->err){ if ($sth->err){
$res->{msg} = "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"; return {msg => "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"};
return $res;
} }
$self->app->log->info("Room $name created by " . $self->session('name')); $self->app->log->info("Room $name created by " . $self->session('name'));
# Etherpad integration ? If so, create the corresponding pad # Etherpad integration ? If so, create the corresponding pad
if ($ec){ if ($ec){
$self->create_pad($name); $self->create_pad($name);
} }
$res->{status} = 1; return {status => 1};
$res->{msg} = 'ROOM_CREATED';
return $res;
}; };
# Take a string as argument # Take a string as argument
@ -235,18 +215,15 @@ helper get_room_by_name => sub {
WHERE `name`=?'); WHERE `name`=?');
}; };
if ($@){ if ($@){
$res->{msg} = $@; return {msg => $@};
return $res;
} }
$sth->execute($name); $sth->execute($name);
if ($sth->err){ if ($sth->err){
$res->{msg} = "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"; return {msg => "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"};
return $res;
} }
$res->{status} = 1; return {
$res->{msg} = ''; data => $sth->fetchall_hashref('name')->{$name}
$res->{data} = $sth->fetchall_hashref('name')->{$name}; };
return $res;
}; };
# Same as before, but take a room ID as argument # Same as before, but take a room ID as argument
@ -270,7 +247,6 @@ helper get_room_by_id => sub {
return {msg => "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"}; return {msg => "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"};
} }
return { return {
status => 1,
data => $sth->fetchall_hashref('id')->{$id} data => $sth->fetchall_hashref('id')->{$id}
}; };
}; };

Loading…
Cancel
Save