From 3b99238cbf9df3575c0e499729da68b6330456be Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 7 May 2014 16:55:39 +0200 Subject: [PATCH] Add a join button on conflict error Cleanup stash handling for the error template, and add a button to join the room Should fix #12 --- lib/Vroom/I18N/en.pm | 1 + lib/Vroom/I18N/fr.pm | 1 + public/vroom.pl | 46 ++++++++++++++++++++++++++++------------- templates/default/error.html.ep | 9 ++++++-- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/lib/Vroom/I18N/en.pm b/lib/Vroom/I18N/en.pm index 08d6f1f..e478d67 100644 --- a/lib/Vroom/I18N/en.pm +++ b/lib/Vroom/I18N/en.pm @@ -27,6 +27,7 @@ our %Lexicon = ( "THANKS_SEE_YOU_SOON" => "Thanks and see you soon", "THANKS_FOR_USING" => "Thank you for using VROOM, we hope you enjoyed your meeting", "BACK_TO_MAIN_MENU" => "Back to main menu", + "JOIN_THIS_ROOM" => "Join this room", "CREATE_ROOM" => "Create a new room", "ROOM_NAME" => "Room name", "RANDOM_IF_EMPTY" => "If you let this field empty, a random name will be given to the room", diff --git a/lib/Vroom/I18N/fr.pm b/lib/Vroom/I18N/fr.pm index 7f5f5ce..470eae2 100644 --- a/lib/Vroom/I18N/fr.pm +++ b/lib/Vroom/I18N/fr.pm @@ -30,6 +30,7 @@ our %Lexicon = ( "THANKS_FOR_USING" => "Nous vous remmercions de votre confiance, et espérons que " . "vous avez passé une agréable réunion.", "BACK_TO_MAIN_MENU" => "Retour au menu principal", + "JOIN_THIS_ROOM" => "Rejoindre ce salon", "CREATE_ROOM" => "Créer un salon", "ROOM_NAME" => "Nom du salon", "RANDOM_IF_EMPTY" => "Si vous laissez ce champs vide, un nom aléatoire sera donné au salon", diff --git a/public/vroom.pl b/public/vroom.pl index 840f8b8..966db76 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -240,16 +240,22 @@ post '/create' => sub { my $name = $self->param('roomName') || lc guid_string(); $self->login; unless ($self->valid_room_name($name)){ - $self->stash(msg => $self->l('ERROR_NAME_INVALID')); - return $self->render('error'); + return $self->render('error', + room => $name, + msg => $self->l('ERROR_NAME_INVALID'), + err => 'ERROR_NAME_INVALID' + ); } $self->delete_rooms; - if ($self->create_room($name,$self->session('name'))){ - $self->redirect_to('/'.$name); + unless ($self->create_room($name,$self->session('name'))){ + return $self->render('error', + room => $name, + msg => $self->l('ERROR_NAME_CONFLICT'), + err => 'ERROR_NAME_CONFLICT' + ); } else{ - $self->stash(msg => $self->l('ERROR_NAME_CONFLICT')); - $self->render('error'); + $self->redirect_to('/'.$name); } }; @@ -273,26 +279,38 @@ get '/(*room)' => sub { # Not auth yet, probably a guest $self->login; unless ($self->valid_room_name($room)){ - $self->stash(msg => 'ERROR_NAME_INVALID'); - return $self->render('error'); + return $self->render('error', + msg => $self->l('ERROR_NAME_INVALID'), + err => 'ERROR_NAME_INVALID', + room => $room + ); } my $data = $self->get_room($room); unless ($data){ - $self->stash(msg => sprintf ($self->l("ERROR_ROOM_s_DOESNT_EXIST"), $room)); - return $self->render('error'); + return $self->render('error', + err => 'ERROR_ROOM_s_DOESNT_EXIST', + msg => sprintf ($self->l("ERROR_ROOM_s_DOESNT_EXIST"), $room), + room => $room + ); } $self->cookie(vroomsession => encode_base64($self->session('name') . ':' . $data->{name} . ':' . $data->{token}, ''), {expires => time + 60}); my @participants = $self->get_participants($room); if ($data->{'locked'}){ unless (($self->session('name') eq $data->{'owner'}) || (grep { $_ eq $self->session('name') } @participants )){ - $self->stash(msg => sprintf($self->l("ERROR_ROOM_s_LOCKED"), $room)); - return $self->render('error'); + return $self->render('error', + msg => sprintf($self->l("ERROR_ROOM_s_LOCKED"), $room), + err => 'ERROR_ROOM_s_LOCKED', + room => $room + ); } } # Add this user to the participants table unless($self->add_participant($room,$self->session('name'))){ - $self->stash(msg => $self->l('ERROR_OCCURED')); - return $self->render('error'); + return $self->render('error', + msg => $self->l('ERROR_OCCURED'), + err => 'ERROR_OCCURED', + room => $room + ); } $self->stash(locked => $data->{locked} ? 'checked':'', turnPassword => $data->{token}); diff --git a/templates/default/error.html.ep b/templates/default/error.html.ep index feb11d0..5d6fc9b 100644 --- a/templates/default/error.html.ep +++ b/templates/default/error.html.ep @@ -4,8 +4,13 @@

<%=l 'ERROR_OCCURED' %>

-

<%=l "$msg" %>

-

<%=l 'BACK_TO_MAIN_MENU' %>

+

<%= $msg %>

+
+ <%=l 'BACK_TO_MAIN_MENU' %> + <% if ($err eq 'ERROR_NAME_CONFLICT'){ %> + <%=l 'JOIN_THIS_ROOM' %> + <% } %> +
%= include 'footer'