Rename status to ok on function return

so it's not confused with json responses (which contains a status element)
master
Daniel Berteaud 10 years ago
parent 8b0dfdccce
commit c195448b05
  1. 30
      vroom.pl

@ -99,7 +99,7 @@ helper valid_room_name => sub {
elsif (grep { $name eq $_ } @reserved){ elsif (grep { $name eq $_ } @reserved){
return {msg => 'ERROR_NAME_RESERVED'}; return {msg => 'ERROR_NAME_RESERVED'};
} }
return {status => 1}; return {ok => 1};
}; };
# Check id arg is a valid ID number # Check id arg is a valid ID number
@ -109,7 +109,7 @@ helper valid_id => sub {
if ($id !~ m/^\d+$/){ if ($id !~ m/^\d+$/){
return {msg => 'INVALID_ID'}; return {msg => 'INVALID_ID'};
} }
return {status => 1, msg => 'OK'}; return {ok => 1};
}; };
########################## ##########################
@ -121,7 +121,7 @@ helper login => sub {
my $self = shift; my $self = shift;
my $ret = {}; my $ret = {};
if ($self->session('name')){ if ($self->session('name')){
return {status => 1}; return {ok => 1};
} }
my $login = $ENV{'REMOTE_USER'} || lc $self->get_random(256); my $login = $ENV{'REMOTE_USER'} || lc $self->get_random(256);
$self->session( $self->session(
@ -129,7 +129,7 @@ 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);
return {status => 1}; return {ok => 1};
}; };
# Expire the cookie # Expire the cookie
@ -143,7 +143,7 @@ helper logout => sub {
} }
$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");
return {status => 1}; return {ok => 1};
}; };
# Create a new room in the DB # Create a new room in the DB
@ -158,7 +158,7 @@ helper create_room => sub {
} }
# Check if the name is valid # Check if the name is valid
$res = $self->valid_room_name($name); $res = $self->valid_room_name($name);
if (!$res->{status}){ if (!$res->{ok}){
return $res; return $res;
} }
$res = $self->get_room_by_name($name); $res = $self->get_room_by_name($name);
@ -197,7 +197,7 @@ helper create_room => sub {
if ($ec){ if ($ec){
$self->create_pad($name); $self->create_pad($name);
} }
return {status => 1}; return {ok => 1};
}; };
# Take a string as argument # Take a string as argument
@ -206,7 +206,7 @@ helper get_room_by_name => sub {
my $self = shift; my $self = shift;
my ($name) = @_; my ($name) = @_;
my $res = $self->valid_room_name($name); my $res = $self->valid_room_name($name);
if (!$res->{status}){ if (!$res->{ok}){
return $res; return $res;
} }
my $sth = eval { my $sth = eval {
@ -231,7 +231,7 @@ helper get_room_by_id => sub {
my $self = shift; my $self = shift;
my ($id) = @_; my ($id) = @_;
my $res = $self->valid_id($id); my $res = $self->valid_id($id);
if (!$res->{status}){ if (!$res->{ok}){
return $res; return $res;
} }
my $sth = eval { my $sth = eval {
@ -255,7 +255,7 @@ helper get_room_by_id => sub {
helper modify_room => sub { helper modify_room => sub {
my $self = shift; my $self = shift;
my ($room) = @_; my ($room) = @_;
# TODO: input validation my $res = {};
my $sth = eval { my $sth = eval {
$self->db->prepare('UPDATE `rooms` $self->db->prepare('UPDATE `rooms`
SET `owner`=?, SET `owner`=?,
@ -283,7 +283,7 @@ helper modify_room => sub {
helper lock_room => sub { helper lock_room => sub {
my $self = shift; my $self = shift;
my ($name,$lock) = @_; my ($name,$lock) = @_;
return undef unless ( $self->get_room_by_name($name)->{status} ); return undef unless ( $self->get_room_by_name($name)->{ok} );
return undef unless ($lock =~ m/^0|1$/); return undef unless ($lock =~ m/^0|1$/);
my $sth = eval { my $sth = eval {
$self->db->prepare('UPDATE `rooms` $self->db->prepare('UPDATE `rooms`
@ -1047,7 +1047,7 @@ post '/create' => sub {
# Cleanup unused rooms before trying to create it # Cleanup unused rooms before trying to create it
$self->delete_rooms; $self->delete_rooms;
my $res = $self->valid_room_name($name); my $res = $self->valid_room_name($name);
if (!$res->{status}){ if (!$res->{ok}){
$json->{err} = $res->{msg}; $json->{err} = $res->{msg};
$json->{msg} = $self->l($res->{msg}); $json->{msg} = $self->l($res->{msg});
return $self->render(json => $json); return $self->render(json => $json);
@ -1058,7 +1058,7 @@ post '/create' => sub {
return $self->render(json => $json); return $self->render(json => $json);
} }
$res = $self->create_room($name,$self->session('name')); $res = $self->create_room($name,$self->session('name'));
if (!$res->{status}){ if (!$res->{ok}){
$json->{err} = $res->{msg}; $json->{err} = $res->{msg};
$json->{msg} = $self->l($res->{msg}); $json->{msg} = $self->l($res->{msg});
return $self->render(json => $json); return $self->render(json => $json);
@ -1144,7 +1144,7 @@ get '/(*room)' => sub {
$self->delete_rooms; $self->delete_rooms;
$self->delete_invitations; $self->delete_invitations;
my $res = $self->valid_room_name($room); my $res = $self->valid_room_name($room);
if (!$res->{status}){ if (!$res->{ok}){
return $self->render('error', return $self->render('error',
msg => $self->l($res->{msg}), msg => $self->l($res->{msg}),
err => $res->{msg}, err => $res->{msg},
@ -1235,7 +1235,7 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
} }
# Sanity check on the room name # Sanity check on the room name
my $res = $self->valid_room_name($room); my $res = $self->valid_room_name($room);
if (!$res->{status}){ if (!$res->{ok}){
return $self->render( return $self->render(
json => { json => {
msg => $self->l($res->{msg}), msg => $self->l($res->{msg}),

Loading…
Cancel
Save