Fix CAPTCHA and flash error for spam

This commit is contained in:
swag 2022-01-02 17:53:43 -05:00
parent 837304d565
commit 13e89cdfa1
2 changed files with 8 additions and 6 deletions

View File

@ -68,14 +68,15 @@ any [qw{GET POST}], '/sign' => sub ($c) {
my $name = $c->param('name') || 'Anonymous'; my $name = $c->param('name') || 'Anonymous';
my $url = $c->param('url'); my $url = $c->param('url');
my $message = $c->param('message'); my $message = $c->param('message');
my $spam = $c->param('answer') ? 0 : 1; my $spam =
!$c->param('answer') ? 1 :
# No URLs in message body since they have their own field $message =~ /$RE{URI}{HTTP}{-scheme => qr<https?>}/ ? 1 :
$spam = 0;
$message =~ /$RE{URI}{HTTP}{-scheme => qr<https?>}/ ? 1 : 0;
if ($message) { if ($message) {
$c->message->create_post($name, $message, $url, $spam); $c->message->create_post($name, $message, $url, $spam);
$c->flash(error => 'This message was flagged as spam') if $spam;
$c->redirect_to('index'); $c->redirect_to('index');
} }
else { else {

View File

@ -16,7 +16,8 @@
<div class="error"> <div class="error">
<h2>Stop! You've violated the law:</h2> <h2>Stop! You've violated the law:</h2>
<p><%= flash 'error' %></p> <p><%= flash 'error' %></p>
<p>This incident has been reported to the cyber-police.</p> <p>Please report to the
<%= link_to 'cyber police', 'mailto:swaggboi@slackware.uk' %>!</p>
</div> </div>
<% } =%> <% } =%>
<hr> <hr>