Handle join auth through the invitation token

master
Daniel Berteaud 11 years ago
parent 20d1bf695f
commit 50cab2837f
  1. 20
      public/vroom.pl
  2. 4
      templates/default/invite.email_html.ep
  3. 2
      templates/default/invite.email_text.ep

@ -533,6 +533,21 @@ helper delete_invitations => sub {
return 1; return 1;
}; };
# Check an invitation token is valid
helper check_invite_token => sub {
my $self = shift;
my ($room,$token) = @_;
my $ret = 0;
my $data = $self->get_room($room);
if (!$data || !$token){
return undef;
}
my $sth = eval { $self->db->prepare("SELECT * FROM `invitations` WHERE id=? AND token=? AND (`response` IS NULL OR `response`='later');") } || return undef;
$sth->execute($data->{id},$token) || return undef;
$ret = 1 if ($sth->rows == 1);
return $ret;
};
# Route / to the index page # Route / to the index page
any '/' => 'index'; any '/' => 'index';
@ -734,6 +749,7 @@ get '/(*room)' => sub {
my $self = shift; my $self = shift;
my $room = $self->stash('room'); my $room = $self->stash('room');
my $video = $self->param('video') || '1'; my $video = $self->param('video') || '1';
my $token = $self->param('token') || undef;
# Redirect to lower case # Redirect to lower case
if ($room ne lc $room){ if ($room ne lc $room){
$self->redirect_to($self->get_url('/') . lc $room); $self->redirect_to($self->get_url('/') . lc $room);
@ -766,7 +782,9 @@ get '/(*room)' => sub {
); );
} }
# Now, if the room is password protected and we're not a participant, nor the owner, lets prompt for the password # Now, if the room is password protected and we're not a participant, nor the owner, lets prompt for the password
if ($data->{join_password} && (!$self->session($room) || $self->session($room)->{role} !~ m/^participant|owner$/)){ if ($data->{join_password} &&
(!$self->session($room) || $self->session($room)->{role} !~ m/^participant|owner$/) &&
!$self->check_invite_token($room,$token)){
return $self->redirect_to($self->get_url('/password') . $room); return $self->redirect_to($self->get_url('/password') . $room);
} }
# Set this peer as a simple participant if he has no role yet (shouldn't happen) # Set this peer as a simple participant if he has no role yet (shouldn't happen)

@ -20,8 +20,8 @@
<%=l 'WHEN_YOU_ARE_READY' %> <%=l 'WHEN_YOU_ARE_READY' %>
<center> <center>
<h1> <h1>
<a href="<%= $url . $room %>"> <a href="<%= $url . $room %>?token=<%= $inviteId %>">
<%= $url . $room %> <%= $url . $room %>?token=<%= $inviteId %>
</a> </a>
</h1> </h1>
</center> </center>

@ -10,7 +10,7 @@
<%==l 'WHEN_YOU_ARE_READY' %> <%==l 'WHEN_YOU_ARE_READY' %>
<%== $url . $room %> <%= $url . $room %>?token=<%= $inviteId %>
<% if ($message && $message ne ''){ %> <% if ($message && $message ne ''){ %>
<%==l 'MESSAGE_FROM_ORGANIZER' %>: <%==l 'MESSAGE_FROM_ORGANIZER' %>:

Loading…
Cancel
Save