Prompt for a password in a niver popup

Fix #97
master
Daniel Berteaud 10 years ago
parent a108b81e3a
commit 506b6f12db
  1. 89
      public/js/vroom.js
  2. 25
      templates/default/join.html.ep
  3. 39
      vroom.pl

@ -648,27 +648,80 @@ function initAdminRooms(){
} }
function initJoin(room){ function initJoin(room){
$.ajax({ // Auth input if access is protected
data: { $('#authBeforeJoinPass').on('input', function() {
req: JSON.stringify({ var pass = $('#authBeforeJoinPass').val();
action: 'get_rtc_conf', if (pass.length > 0 && pass.length < 200){
param: { $('#authBeforeJoinButton').removeClass('disabled');
room: room, $('#authBeforeJoinPass').parent().removeClass('has-error');
} }
}) else{
}, $('#authBeforeJoinButton').addClass('disabled');
error: function(data){ $('#authBeforeJoinPass').parent().addClass('has-error');
showApiError(data); if (pass.length < 1){
}, $('#authBeforeJoinPass').notify(localize('PASSWORD_REQUIRED'), 'error');
success: function(data){ }
if (!video){ else{
data.config.media.video = false; $('#authBeforeJoinPass').notify(localize('PASSWORD_TOO_LONG'), 'error');
} }
data.config.localVideoEl = 'webRTCVideoLocal';
webrtc = new SimpleWebRTC(data.config);
initVroom(room);
} }
}); });
$('#authBeforeJoinForm').submit(function(event){
event.preventDefault();
var pass = $('#authBeforeJoinPass').val();
if (pass.length > 0 && pass.length < 200){
$('#auth-before-join').slideUp();
try_auth(pass, true);
}
});
function try_auth(pass, hideErrorMsg){
$.ajax({
data: {
req: JSON.stringify({
action: 'authenticate',
param: {
room: room,
password: pass
}
})
},
error: function(data){
if (data.status === 401){
$('#auth-before-join').slideDown();
}
if (hideErrorMsg){
showApiError(data);
}
},
success: function(data){
$.ajax({
data: {
req: JSON.stringify({
action: 'get_rtc_conf',
param: {
room: room,
}
})
},
error: function(data){
showApiError(data);
},
success: function(data){
if (!video){
data.config.media.video = false;
}
data.config.localVideoEl = 'webRTCVideoLocal';
webrtc = new SimpleWebRTC(data.config);
initVroom(room);
}
});
}
});
}
try_auth('', false);
} }
// This is the main function called when you join a room // This is the main function called when you join a room

@ -236,6 +236,31 @@
</a> </a>
</p> </p>
</div> </div>
<div id="auth-before-join" class="connecting-msg" style="display: none">
<form role="form" class="form-horizontal" id="authBeforeJoinForm">
<p class="text-center">
<%=l 'A_PASSWORD_IS_NEEDED_TO_JOIN' %>
</p>
<div class="form-group">
<label for="authBeforJoinPass" class="col-sm-4 control-label">
<%=l 'PASSWORD' %>
</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="authBeforeJoinPass" placeholder="<%=l 'PASSWORD' %>">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button id="authBeforeJoinButton" class="btn btn-primary disabled" type="submit">
<%=l 'SUBMIT' %>
</button>
<a class="btn btn-default" href="<%= $self->url_for('/') %>">
<%=l 'CANCEL' %>
</a>
</div>
</div>
</form>
</div>
<div id="display-name-pre" class="connecting-msg" style="display: none"> <div id="display-name-pre" class="connecting-msg" style="display: none">
<form role="form" class="form-horizontal" id="displayNamePreForm"> <form role="form" class="form-horizontal" id="displayNamePreForm">
<p class="text-center"> <p class="text-center">

@ -1514,10 +1514,9 @@ any '/api' => sub {
# Ok, now, we don't have to bother with authorization anymore # Ok, now, we don't have to bother with authorization anymore
if ($req->{action} eq 'authenticate'){ if ($req->{action} eq 'authenticate'){
my $pass = $req->{param}->{pass}; my $pass = $req->{param}->{password};
# Is this peer already authenticated ? # Is this peer already authenticated ?
my $role = $self->get_key_role($token, $room->{name}); my $role = $self->get_key_role($token, $room->{name});
$self->app->log->debug("Checking pass $pass");
if ($room->{owner_password} && Crypt::SaltedHash->validate($room->{owner_password}, $pass)){ if ($room->{owner_password} && Crypt::SaltedHash->validate($room->{owner_password}, $pass)){
$role = 'owner'; $role = 'owner';
} }
@ -1526,6 +1525,9 @@ any '/api' => sub {
} }
if ($role){ if ($role){
$self->session($room->{name}, {role => $role}); $self->session($room->{name}, {role => $role});
if ($ec && !$self->session($room->{name})->{etherpadSession}){
$self->create_etherpad_session();
}
$self->set_peer_role({ $self->set_peer_role({
room => $room->{name}, room => $room->{name},
peer_id => $self->session('peer_id'), peer_id => $self->session('peer_id'),
@ -1545,7 +1547,7 @@ any '/api' => sub {
} }
return $self->render( return $self->render(
json => { json => {
msg => $self->l('AUTH_NEEDED') msg => $self->l('WRONG_PASSWORD')
}, },
status => '401' status => '401'
); );
@ -2089,32 +2091,11 @@ get '/:room' => sub {
room => $room, room => $room,
); );
} }
# Now, if the room is password protected and we're not a participant, nor the owner, lets prompt for the password # pad doesn't exist yet ?
# Email invitation have a token which can be used instead of password if ($ec && !$data->{etherpad_group}){
if ($data->{join_password} && $self->create_pad($room);
(!$self->session($room) || # Reload data so we get the etherpad_group
$self->session($room)->{role} !~ m/^participant|owner$/) && $data = $self->get_room_by_name($room);
!$self->check_invite_token($room,$token)){
return $self->redirect_to($self->url_for('/password/') . $room);
}
# Set this peer as a simple participant if he has no role yet (shouldn't happen)
if (!$self->session($room) || !$self->session($room)->{role}){
$self->session($room => {role => 'participant'});
$self->associate_key_to_room(
room => $room,
key => $self->session('key'),
role => 'participant'
);
}
# Create etherpad session if needed
if ($ec && !$self->session($room)->{etherpadSession}){
# pad doesn't exist yet ?
if (!$data->{etherpad_group}){
$self->create_pad($room);
# Reload data so we get the etherpad_group
$data = $self->get_room_by_name($room);
}
$self->create_etherpad_session($room);
} }
# Now display the room page # Now display the room page
return $self->render('join', return $self->render('join',

Loading…
Cancel
Save