From cdc4d71e6813168711c0c3cafb3f2c327bc90ff4 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 22 Jan 2015 12:56:48 +0100 Subject: [PATCH] Hook the new config menu with a new update_room_conf api method --- lib/Vroom/Constants.pm | 3 ++- lib/Vroom/I18N/en.pm | 1 + lib/Vroom/I18N/fr.pm | 1 + public/js/vroom.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vroom.pl | 27 +++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index 3198f57..5114451 100644 --- a/lib/Vroom/Constants.pm +++ b/lib/Vroom/Constants.pm @@ -167,7 +167,8 @@ use constant API_ACTIONS => { email_notification => 1, promote_peer => 1, wipe_data => 1, - delete_room => 1 + delete_room => 1, + update_room_conf => 1 }, participant => { ping => 1, diff --git a/lib/Vroom/I18N/en.pm b/lib/Vroom/I18N/en.pm index 2ce8a6c..fdeb20d 100644 --- a/lib/Vroom/I18N/en.pm +++ b/lib/Vroom/I18N/en.pm @@ -142,6 +142,7 @@ our %Lexicon = ( "NOTIFICATION_ON_JOIN" => "Email addresses to notify when someone joins this room", "s_WILL_BE_NOTIFIED" => "%s will receive a notification each time someone joins this room", "s_WONT_BE_NOTIFIED_ANYMORE" => "%s won't be notified anymore", + "ROOM_CONFIG_UPDATED" => "Room configuration has been updated", "s_JOINED_ROOM_s" => "%s joined room %s", "SOMEONE" => "Someone", "SOMEONE_JOINED_A_ROOM" => "Someone joined a video conference room, and your address is configured to receive " . diff --git a/lib/Vroom/I18N/fr.pm b/lib/Vroom/I18N/fr.pm index c729cc7..ecffaae 100644 --- a/lib/Vroom/I18N/fr.pm +++ b/lib/Vroom/I18N/fr.pm @@ -149,6 +149,7 @@ our %Lexicon = ( "NOTIFICATION_ON_JOIN" => "Email à notifier lorsque quelqu'un rejoint ce salon", "s_WILL_BE_NOTIFIED" => "%s recevra une notification à chaque fois qu'une personne rejoint ce salon", "s_WONT_BE_NOTIFIED_ANYMORE" => "%s ne recevra plus les notifications pour ce salon", + "ROOM_CONFIG_UPDATED" => "La configuration du salon a été mise à jour", "s_JOINED_ROOM_s" => "%s a rejoint le salon %s", "SOMEONE" => "Quelqu'un", "SOMEONE_JOINED_A_ROOM" => "Quelqu'un a rejoint un salon de vidéo conférence, et votre adresse est configurée " . diff --git a/public/js/vroom.js b/public/js/vroom.js index a3bda50..6520919 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -2031,6 +2031,8 @@ function initVroom(room) { $('#ownerPassFields').hide(200); } }); + + // Create a new input field function addEmailInputField(val){ var parentEl = $('.email-list'), currentEntry = parentEl.find('.email-entry:last'), @@ -2051,6 +2053,51 @@ function initVroom(room) { $(this).parents('.email-entry:first').remove(); }); + // Submit the configuration form + $('#configureRoomForm').submit(function(e){ + e.preventDefault(); + // TODO: validate password and email here + // or disable the submit button and validate as you type ? + var locked = $('#lockedSet').bootstrapSwitch('state'), + askForName = $('#askForNameSet').bootstrapSwitch('state'), + joinPass = ($('#joinPassSet').bootstrapSwitch('state')) ? + $('#joinPass').val() : false, + ownerPass = ($('#ownerPassSet').bootstrapSwitch('state')) ? + $('#ownerPass').val() : false, + emails = []; + $('input[name="emails[]"]').each(function(){ + emails.push($(this).val()); + }); + $.ajax({ + data: { + req: JSON.stringify({ + action: 'update_room_conf', + param: { + room: roomName, + locked: locked, + ask_for_name: askForName, + join_password: joinPass, + owner_password: ownerPass, + emails: emails + } + }) + }, + error: function() { + $.notify(locale.ERROR_OCCURRED, 'error'); + }, + success: function(data) { + $('#ownerPass,#ownerPassConfirm,#joinPass,#joinPassConfirm').val(''); + if (data.status == 'success'){ + $.notify(data.msg, 'info'); + webrtc.sendToAll('room_conf_updated'); + } + else{ + $.notify(data.msg, 'error'); + } + } + }); + }); + $('#ownerPassButton').change(function(){ var action = ($(this).is(':checked')) ? 'set':'unset'; if (action == 'set'){ diff --git a/vroom.pl b/vroom.pl index 960099a..03f54a0 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1336,6 +1336,33 @@ any '/api' => sub { } ); } + # Update room configuration + elsif ($req->{action} eq 'update_room_conf'){ + $room->{locked} = ($req->{param}->{locked}) ? '1' : '0'; + $room->{ask_for_name} = ($req->{param}->{ask_for_name}) ? '1' : '0'; + foreach my $pass (qw/join_password owner_password/){ + if (!$req->{param}->{$pass}){ + $room->{$pass} = undef; + } + elsif ($req->{param}->{$pass} ne ''){ + $room->{$pass} = Crypt::SaltedHash->new(algorithm => 'SHA-256')->add($req->{param}->{$pass})->generate; + } + } + if ($self->modify_room($room)){ + return $self->render( + json => { + status => 'success', + msg => $self->l('ROOM_CONFIG_UPDATED') + } + ); + } + return $self->render( + json => { + status => 'error', + msg => $self->l('ERROR_OCCURRED') + } + ); + } # Handle password (join and owner) elsif ($req->{action} eq 'set_join_password'){ $room->{join_password} = ($req->{param}->{password} && $req->{param}->{password} ne '') ?