diff --git a/lib/Vroom/I18N/en.pm b/lib/Vroom/I18N/en.pm index 21869b2..2fd11dd 100644 --- a/lib/Vroom/I18N/en.pm +++ b/lib/Vroom/I18N/en.pm @@ -67,6 +67,12 @@ our %Lexicon = ( "REMOVE_PASSWORD" => "Remove the password", "PASSWORD_SET" => "Password updated", "PASSWORD_REMOVED" => "Password removed", + "AUTHENTICATE" => "Authentication", + "AUTH_TO_MANAGE_THE_ROOM" => "Authenticate to manage the room", + "OWNER_PASSWORD_MAKES_PERSISTENT" => "You can set a manager password. It will make this room persistent", + "OWNER_PASSWORD" => "Manager password", + "REMOVE_OWNER_PASSWORD" => "Remove the manager password. The room will become ephemeral", + "AUTH_SUCCESS" => "You are now authenticated", "NOT_ALLOWED" => "You are not allowed to do this", "WRONG_PASSWORD" => "Wrong password", "PASSWORD_REQUIRED" => "Password required", diff --git a/lib/Vroom/I18N/fr.pm b/lib/Vroom/I18N/fr.pm index 877540e..8cc7245 100644 --- a/lib/Vroom/I18N/fr.pm +++ b/lib/Vroom/I18N/fr.pm @@ -73,6 +73,12 @@ our %Lexicon = ( "REMOVE_PASSWORD" => "Supprimer le mot de passe", "PASSWORD_SET" => "Le mot de passe a été mis à jour", "PASSWORD_REMOVED" => "Le mot de passe a été supprimé", + "AUTHENTICATE" => "Authentification", + "AUTH_TO_MANAGE_THE_ROOM" => "Authentifiez-vous pour gérer le salon", + "OWNER_PASSWORD_MAKES_PERSISTENT" => "Vous pouvez ajouter un mot de passe de gestionnaire. Ceci rendra le salon persistant", + "OWNER_PASSWORD" => "Mot de passe du gestionnaire", + "REMOVE_OWNER_PASSWORD" => "Supprimer le mot de passe du gestionnaire. Le salon redeviendra éphémère", + "AUTH_SUCCESS" => "Vous êtes maintenant authentifié", "NOT_ALLOWED" => "Vous n'êtes pas autorisé à faire ceci", "WRONG_PASSWORD" => "Mauvais mot de passe", "PASSWORD_REQUIRED" => "Mot de passe requis", diff --git a/public/css/vroom.css b/public/css/vroom.css index 379a88a..41e6c52 100644 --- a/public/css/vroom.css +++ b/public/css/vroom.css @@ -79,9 +79,15 @@ #confMenu { min-width: 400px; } +#authMenu { + min-width: 400px; +} .ownerEl { display: none; } +.unauthEl{ + display: none; +} #chatBox { max-height:300px; resize:none; diff --git a/public/js/vroom.js b/public/js/vroom.js index 96c1430..c87c5b0 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -122,13 +122,17 @@ function initVroom(room) { $.notify(locale.ERROR_OCCURED, 'error'); }, success: function(data) { - peers.local.role = data.msg; + peers.local.role = data.role; // Enable owner reserved menu - if (data.msg == 'owner'){ + if (data.role == 'owner'){ + $('.unauthEl').hide(500); $('.ownerEl').show(500); } else{ $('.ownerEl').hide(500); + if (data.auth == 'yes'){ + $('.unauthEl').show(500); + } } } }); @@ -455,11 +459,17 @@ function initVroom(room) { if (peers.local.role == 'owner'){ $.notify(sprintf(locale.OWNER_PASSWORD_CHANGED_BY_s, stringEscape(peers[data.id].displayName)), 'warn'); } + else{ + updateRole(); + } }); webrtc.on('owner_password_removed', function(data){ if (peers.local.role == 'owner'){ $.notify(sprintf(locale.OWNER_PASSWORD_REMOVED_BY_s, stringEscape(peers[data.id].displayName)), 'warn'); } + else{ + updateRole(); + } }); // Handle the readyToCall event: join the room @@ -624,6 +634,43 @@ function initVroom(room) { } }); + // Handle auth + $('#authPass').on('input', function() { + if ($('#authPass').val() == ''){ + $('#authPassButton').addClass('disabled'); + } + else{ + $('#authPassButton').removeClass('disabled'); + } + }); + $('#authForm').submit(function(event) { + event.preventDefault(); + var pass = $('#authPass').val(); + $.ajax({ + data: { + action: 'authenticate', + password: pass, + room: roomName + }, + error: function(data) { + var msg = locale.ERROR_OCCURED; + $.notify(msg, 'error'); + }, + success: function(data) { + $('#authPass').val(''); + if (data.status == 'success'){ + updateRole(); + $.notify(data.msg, 'success'); + } + else{ + $.notify(data.msg, 'error'); + } + // Close the auth menu + $('#authMenu').dropdown('toggle'); + } + }); + }); + $('#joinPass').on('input', function() { if ($('#joinPass').val() == ''){ $('#setJoinPassButton').addClass('disabled'); diff --git a/public/vroom.pl b/public/vroom.pl index 84233de..6886476 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -551,10 +551,34 @@ post '/action' => sub { ); } } + elsif ($action eq 'authenticate'){ + my $pass = $self->param('password'); + my $res = undef; + my $msg = 'ERROR_OCCURED'; + my $status = 'error'; + if ($data->{owner_password} && Crypt::SaltedHash->validate($data->{owner_password}, $pass)){ + $self->session($room, {role => 'owner'}); + $msg = 'AUTH_SUCCESS'; + $status = 'success'; + } + elsif ($data->{owner_password}){ + $msg = 'WRONG_PASSWORD'; + } + else{ + $msg = 'NOT_ALLOWED'; + } + return $self->render( + json => { + msg => $self->l($msg), + status => $status + }, + ); + } elsif ($action eq 'getRole'){ return $self->render( json => { - msg => $self->session($room)->{role}, + role => $self->session($room)->{role}, + auth => ($data->{owner_password}) ? 'yes' : 'no', status => 'success' }, ); diff --git a/templates/default/join.html.ep b/templates/default/join.html.ep index a80e3e6..ac1b66e 100644 --- a/templates/default/join.html.ep +++ b/templates/default/join.html.ep @@ -130,6 +130,30 @@ +