Various cleanups in invitations handling

master
Daniel Berteaud 11 years ago
parent 50cab2837f
commit 2a437cc4fd
  1. 17
      public/vroom.pl
  2. 6
      templates/default/invitation.html.ep
  3. 11
      templates/default/invite.email_html.ep
  4. 9
      templates/default/invite.email_text.ep

@ -476,7 +476,7 @@ helper add_invitation => sub {
my ($room,$email) = @_; my ($room,$email) = @_;
my $from = $self->session('name') || return undef; my $from = $self->session('name') || return undef;
my $data = $self->get_room($room); my $data = $self->get_room($room);
my $id = $self->get_random(20); my $id = $self->get_random(30);
return undef unless ($data); return undef unless ($data);
my $sth = eval { $self->db->prepare("INSERT INTO `invitations` (`id`,`from`,`token`,`email`,`timestamp`) VALUES (?,?,?,?,?)") } || return undef; my $sth = eval { $self->db->prepare("INSERT INTO `invitations` (`id`,`from`,`token`,`email`,`timestamp`) VALUES (?,?,?,?,?)") } || return undef;
$sth->execute($data->{id},$from,$id,$email,time()) || return undef; $sth->execute($data->{id},$from,$id,$email,time()) || return undef;
@ -620,11 +620,12 @@ get '/kicked/(:room)' => sub {
# Route for invitition response # Route for invitition response
get '/invitation' => sub { get '/invitation' => sub {
my $self = shift; my $self = shift;
my $inviteId = $self->param('id') || ''; my $inviteId = $self->param('token') || '';
my $response = $self->param('response') || 'decline'; # Delecte expired invitation now
$self->delete_invitations;
my $invite = $self->get_invitation($inviteId); my $invite = $self->get_invitation($inviteId);
my $room = $self->get_room_by_id($invite->{id}); my $room = $self->get_room_by_id($invite->{id});
if (!$invite || !$room || $response !~ m/^(decline|later)$/){ if (!$invite || !$room){
return $self->render('error', return $self->render('error',
err => 'ERROR_INVITATION_INVALID', err => 'ERROR_INVITATION_INVALID',
msg => $self->l('ERROR_INVITATION_INVALID'), msg => $self->l('ERROR_INVITATION_INVALID'),
@ -634,13 +635,12 @@ get '/invitation' => sub {
$self->render('invitation', $self->render('invitation',
inviteId => $inviteId, inviteId => $inviteId,
room => $room->{name}, room => $room->{name},
response => $response
); );
}; };
post '/invitation' => sub { post '/invitation' => sub {
my $self = shift; my $self = shift;
my $id = $self->param('id') || ''; my $id = $self->param('token') || '';
my $response = $self->param('response') || 'decline'; my $response = $self->param('response') || 'decline';
my $message = $self->param('message') || ''; my $message = $self->param('message') || '';
if ($response !~ m/^(later|decline)$/ || !$self->respond_invitation($id,$response,$message)){ if ($response !~ m/^(later|decline)$/ || !$self->respond_invitation($id,$response,$message)){
@ -755,6 +755,7 @@ get '/(*room)' => sub {
$self->redirect_to($self->get_url('/') . lc $room); $self->redirect_to($self->get_url('/') . lc $room);
} }
$self->delete_rooms; $self->delete_rooms;
$self->delete_invitations;
unless ($self->valid_room_name($room)){ unless ($self->valid_room_name($room)){
return $self->render('error', return $self->render('error',
msg => $self->l('ERROR_NAME_INVALID'), msg => $self->l('ERROR_NAME_INVALID'),
@ -782,6 +783,7 @@ 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
# Email invitation have a token which can be used instead of password
if ($data->{join_password} && if ($data->{join_password} &&
(!$self->session($room) || $self->session($room)->{role} !~ m/^participant|owner$/) && (!$self->session($room) || $self->session($room)->{role} !~ m/^participant|owner$/) &&
!$self->check_invite_token($room,$token)){ !$self->check_invite_token($room,$token)){
@ -864,7 +866,8 @@ post '/action' => sub {
template => 'invite', template => 'invite',
room => $room, room => $room,
message => $message, message => $message,
inviteId => $inviteId inviteId => $inviteId,
joinPass => ($data->{join_password}) ? 'yes' : 'no'
], ],
)){ )){
$self->app->log->info($self->session('name') . " sent an invitation for room $room to $rcpt"); $self->app->log->info($self->session('name') . " sent an invitation for room $room to $rcpt");

@ -26,16 +26,16 @@
<textarea name="message" id="message" class="form-control" rows="5" placeholder="<%=l 'DONT_WAIT_FOR_ME' %>"></textarea> <textarea name="message" id="message" class="form-control" rows="5" placeholder="<%=l 'DONT_WAIT_FOR_ME' %>"></textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="response"><%=l 'YOU_CAN_STILL_CHANGE_YOUR_MIND' %></label> <label><%=l 'YOU_CAN_STILL_CHANGE_YOUR_MIND' %></label>
<p> <p>
<%=l 'CLICK_SEND_OR_JOIN_NOW' %> <%=l 'CLICK_SEND_OR_JOIN_NOW' %>
</p> </p>
</div> </div>
<div class="btn-group"> <div class="btn-group">
<button type="submit" class="btn btn-default btn-lg"><%=l 'SUBMIT' %></button> <a class="btn btn-default btn-lg" role="button" href="<%= $self->get_url('/') . $room %><% if ($inviteId ne ''){ %>?token=<%= $inviteId %><% } %>">
<a class="btn btn-primary btn-lg" role="button" href="<%= $self->get_url('/') . $room %>">
<%=l 'JOIN_THIS_ROOM' %> <%=l 'JOIN_THIS_ROOM' %>
</a> </a>
<button type="submit" class="btn btn-primary btn-lg"><%=l 'SUBMIT' %></button>
</div> </div>
</form> </form>
</div> </div>

@ -20,8 +20,13 @@
<%=l 'WHEN_YOU_ARE_READY' %> <%=l 'WHEN_YOU_ARE_READY' %>
<center> <center>
<h1> <h1>
<a href="<%= $url . $room %>?token=<%= $inviteId %>"> <% my $roomAccess = $room;
<%= $url . $room %>?token=<%= $inviteId %> if ($joinPass eq 'yes') {
$roomAccess .= '?token=' . $inviteId;
}
%>
<a href="<%= $url . $roomAccess %>">
<%= $url . $roomAccess %>
</a> </a>
</h1> </h1>
</center> </center>
@ -37,7 +42,7 @@
<p> <p>
<%=l 'IF_YOU_CANNOT_JOIN' %> <%=l 'IF_YOU_CANNOT_JOIN' %>
<h3> <h3>
<a style="color:red" href="<%= $url . 'invitation?id=' . $inviteId %>"> <a style="color:red" href="<%= $url . 'invitation?token=' . $inviteId %>">
<%=l 'YOU_CAN_NOTIFY_THE_ORGANIZER' %> <%=l 'YOU_CAN_NOTIFY_THE_ORGANIZER' %>
</a> </a>
</h3> </h3>

@ -10,7 +10,12 @@
<%==l 'WHEN_YOU_ARE_READY' %> <%==l 'WHEN_YOU_ARE_READY' %>
<%= $url . $room %>?token=<%= $inviteId %> <% my $roomAccess = $room;
if ($joinPass eq 'yes') {
$roomAccess .= '?token=' . $inviteId;
}
%>
<%== $url . $roomAccess %>
<% if ($message && $message ne ''){ %> <% if ($message && $message ne ''){ %>
<%==l 'MESSAGE_FROM_ORGANIZER' %>: <%==l 'MESSAGE_FROM_ORGANIZER' %>:
@ -20,7 +25,7 @@
<%==l 'IF_YOU_CANNOT_JOIN' %> <%==l 'YOU_CAN_NOTIFY_THE_ORGANIZER' %> <%==l 'IF_YOU_CANNOT_JOIN' %> <%==l 'YOU_CAN_NOTIFY_THE_ORGANIZER' %>
<%== $url . 'invitation?id=' . $inviteId %> <%== $url . 'invitation?token=' . $inviteId %>
<%==l 'HAVE_A_NICE_MEETING' %> <%==l 'HAVE_A_NICE_MEETING' %>
-- --

Loading…
Cancel
Save