Implement join password setting

But it's not used yet :-)
master
Daniel Berteaud 11 years ago
parent 950f31c39a
commit 6b4ced06bb
  1. 49
      public/js/vroom.js
  2. 39
      public/vroom.pl

@ -616,6 +616,55 @@ function initVroom(room) {
} }
}); });
$('#joinPass').on('input', function() {
if ($('#joinPass').val() == ''){
$('#setJoinPassButton').addClass('disabled');
}
else{
$('#setJoinPassButton').removeClass('disabled');
}
});
// Join password protection
$('#setJoinPassButton').click(function(event) {
var pass = $('#joinPass').val();
$('#joinPass').val('');
$('#setJoinPassButton').addClass('disabled');
$.ajax({
data: {
action: 'setJoinPassword',
password: pass,
room: roomName
},
error: function(data) {
var msg = (data && data.msg) ? data.msg : locale.ERROR_OCCURED;
$.notify(msg, 'error');
},
success: function(data) {
$.notify(data.msg, 'success');
$('#joinPass').val('');
}
});
});
// Remove password protection
$('#removeJoinPassButton').click(function(event) {
$.ajax({
data: {
action: 'setJoinPassword',
room: roomName
},
error: function(data) {
var msg = (data && data.msg) ? data.msg : locale.ERROR_OCCURED;
$.notify(msg, 'error');
},
success: function(data) {
$.notify(data.msg, 'success');
$('#joinPass').val('');
}
});
});
// Choose another color. Useful if two peers have the same // Choose another color. Useful if two peers have the same
$('#changeColorButton').click(function(){ $('#changeColorButton').click(function(){
peers.local.color = chooseColor(); peers.local.color = chooseColor();

@ -237,6 +237,22 @@ helper get_mtime => sub {
return stat($file)->mtime; return stat($file)->mtime;
}; };
# password protect a room
helper set_join_pass => sub {
my $self = shift;
my ($room,$pass) = @_;
return undef unless ( %{ $self->get_room($room) });
my $sth = eval { $self->db->prepare("UPDATE rooms SET join_password=? where name=?;") } || return undef;
$sth->execute($pass,$room) || return undef;
if ($pass){
$self->app->log->debug($self->session('name') . " has set a password on room $room");
}
else{
$self->app->log->debug($self->session('name') . " has removed password on room $room");
}
return 1;
};
any '/' => 'index'; any '/' => 'index';
get '/about' => sub { get '/about' => sub {
@ -338,7 +354,6 @@ get '/(*room)' => sub {
room => $room room => $room
); );
} }
$self->cookie(vroomsession => encode_base64($self->session('name') . ':' . $data->{name} . ':' . $data->{token}, ''), {expires => time + 60});
my @participants = $self->get_participants($room); my @participants = $self->get_participants($room);
if ($data->{'locked'}){ if ($data->{'locked'}){
unless (($self->session('name') eq $data->{'owner'}) || (grep { $_ eq $self->session('name') } @participants )){ unless (($self->session('name') eq $data->{'owner'}) || (grep { $_ eq $self->session('name') } @participants )){
@ -349,6 +364,8 @@ get '/(*room)' => sub {
); );
} }
} }
# TODO: check join password here
$self->cookie(vroomsession => encode_base64($self->session('name') . ':' . $data->{name} . ':' . $data->{token}, ''), {expires => time + 60});
# Add this user to the participants table # Add this user to the participants table
unless($self->add_participant($room,$self->session('name'))){ unless($self->add_participant($room,$self->session('name'))){
return $self->render('error', return $self->render('error',
@ -455,6 +472,26 @@ post '/action' => sub {
); );
} }
} }
elsif ($action eq 'setJoinPassword'){
my $pass = $self->param('password');
$pass = undef if ($pass eq '');
my $res = $self->set_join_pass($room,$pass);
if (!$res){
return $self->render(
json => {
msg => $self->l('ERROR_OCCURED'),
},
status => '500'
);
}
else{
return $self->render(
json => {
msg => ($pass) ? 'JOIN_PASSWORD_SET':'JOIN_PASSWORD_REMOVED',
}
);
}
}
}; };
# Not found (404) # Not found (404)

Loading…
Cancel
Save