CLeanups in invitation response handling

master
Daniel Berteaud 10 years ago
parent 971b114251
commit 81f1ece9ba
  1. 5
      templates/default/invitation.html.ep
  2. 45
      vroom.pl

@ -3,14 +3,13 @@
%= include 'public_toolbar' %= include 'public_toolbar'
<div class="container-fluid"> <div class="container-fluid">
<div class="well publicForm"> <div class="well publicForm">
<form role="form" action="<%= $self->url_for('/invitation') %>" method="post"> <form role="form" method="post">
<legend class="text-center"> <legend class="text-center">
<%=l 'INVITATION_RESPONSE' %> <%=l 'INVITATION_RESPONSE' %>
</legend> </legend>
<p class="text-center"> <p class="text-center">
<%=l 'CANNOT_JOIN_NOW' %> <%=l 'CANNOT_JOIN_NOW' %>
</p> </p>
<input name="token" type="hidden" value="<%= $inviteId %>"/>
<div class="form-group"> <div class="form-group">
<label for="response"> <label for="response">
<%=l 'WILL_YOU_JOIN' %> <%=l 'WILL_YOU_JOIN' %>
@ -38,7 +37,7 @@
<%=l 'CLICK_SEND_OR_JOIN_NOW' %> <%=l 'CLICK_SEND_OR_JOIN_NOW' %>
</p> </p>
</div> </div>
<a class="btn btn-default btn-lg" role="button" href="<%= $self->get_url('/') . $room %><% if ($inviteId ne ''){ %>?token=<%= $inviteId %><% } %>"> <a class="btn btn-default btn-lg" role="button" href="<%= $self->get_url('/') . $room . '/' . $token %>">
<%=l 'JOIN_THIS_ROOM' %> <%=l 'JOIN_THIS_ROOM' %>
</a> </a>
<button type="submit" class="btn btn-primary btn-lg"> <button type="submit" class="btn btn-primary btn-lg">

@ -684,16 +684,20 @@ helper get_invitation_list => sub {
return $sth->fetchall_hashref('id'); return $sth->fetchall_hashref('id');
}; };
helper respond_invitation => sub { helper respond_to_invitation => sub {
my $self = shift; my $self = shift;
my ($id,$response,$message) = @_; my ($token,$response,$message) = @_;
my $sth = eval { my $sth = eval {
$self->db->prepare('UPDATE `email_invitations` $self->db->prepare('UPDATE `email_invitations`
SET `response`=?, SET `response`=?,
`message`=? `message`=?
WHERE `token`=?'); WHERE `token`=?');
} || return undef; };
$sth->execute($response,$message,$id) || return undef; $sth->execute(
$response,
$message,
$token
);
return 1; return 1;
}; };
@ -885,12 +889,12 @@ get '/kicked/(:room)' => sub {
} => 'kicked'; } => 'kicked';
# Route for invitition response # Route for invitition response
get '/invitation' => sub { any [qw(GET POST)] => '/invitation/:token' => { token => '' } => sub {
my $self = shift; my $self = shift;
my $inviteId = $self->param('token') || ''; my $token = $self->stash('token');
# Delete expired invitation now # Delete expired invitation now
$self->delete_invitations; $self->delete_invitations;
my $invite = $self->get_invitation_by_token($inviteId); my $invite = $self->get_invitation_by_token($token);
my $room = $self->get_room_by_id($invite->{room_id}); my $room = $self->get_room_by_id($invite->{room_id});
if (!$invite || !$room){ if (!$invite || !$room){
return $self->render('error', return $self->render('error',
@ -899,21 +903,20 @@ get '/invitation' => sub {
room => $room room => $room
); );
} }
$self->render('invitation', if ($self->req->method eq 'GET'){
inviteId => $inviteId, return $self->render('invitation',
room => $room->{name}, token => $token,
); room => $room->{name},
}; );
}
post '/invitation' => sub { elsif ($self->req->method eq 'POST'){
my $self = shift; my $response = $self->param('response') || 'decline';
my $id = $self->param('token') || ''; my $message = $self->param('message') || '';
my $response = $self->param('response') || 'decline'; if ($response !~ m/^(later|decline)$/ || !$self->respond_to_invitation($token,$response,$message)){
my $message = $self->param('message') || ''; return $self->render('error');
if ($response !~ m/^(later|decline)$/ || !$self->respond_invitation($id,$response,$message)){ }
return $self->render('error'); return $self->render('invitation_thanks');
} }
$self->render('invitation_thanks');
}; };
# This handler creates a new room # This handler creates a new room

Loading…
Cancel
Save