captcha for flag_remark

This commit is contained in:
swag 2023-06-13 21:32:59 -04:00
parent f4c9d25139
commit d749b1a9c8
6 changed files with 47 additions and 16 deletions

View File

@ -0,0 +1 @@
daniel@graymember.5691

View File

@ -65,18 +65,28 @@ sub create($self) {
sub flag($self) { sub flag($self) {
my $remark_id = $self->param('remark_id'); my $remark_id = $self->param('remark_id');
my $v = $self->validation;
$v->optional(captcha => 'trim')->size(4, 4)->like(qr/flag/i);
if ($v->is_valid) {
my $thread_id = $self->remark->thread_id_for($remark_id); my $thread_id = $self->remark->thread_id_for($remark_id);
my $redirect_url = my $redirect_url =
$self->url_for('single_thread', thread_id => $thread_id) $self->url_for('single_thread', thread_id => $thread_id)
->fragment('info')->to_abs; ->fragment('info')->to_abs;
$self->remark->flag($remark_id); $self->remark->flag($remark_id);
$self->flash( $self->flash(
info => "Remark #$remark_id has been flagged for moderator. 🚩" info => "Remark #$remark_id has been flagged for moderator. 🚩"
); );
$self->redirect_to($redirect_url); return $self->redirect_to($redirect_url);
}
elsif ($v->has_error) {
$self->stash(status => 400)
}
return $self->render;
} }
1; 1;

View File

@ -157,7 +157,7 @@ sub bump($self) {
$self->stash(status => 400) $self->stash(status => 400)
} }
$self->render; return $self->render;
} }
sub flag($self) { sub flag($self) {

View File

@ -48,9 +48,10 @@ subtest 'Flagging remark', sub {
->element_exists('a[href*="flag"]') ->element_exists('a[href*="flag"]')
->text_like(h2 => qr/Remark #1/); ->text_like(h2 => qr/Remark #1/);
$t->get_ok('/remark/flag/1')->status_is(200) $t->get_ok('/remark/flag/1' )->status_is(200);
->element_exists('p[class="stash-with-info"]') $t->get_ok('/remark/flag/65536')->status_is(404);
->text_like(p => qr/Remark #1 has been flagged/); $t->get_ok('/remark/flag/1', form => {captcha => 'flag'})->status_is(200);
$t->get_ok('/remark/flag/1', form => {captcha => 'aaaa'})->status_is(400);
}; };
done_testing; done_testing;

View File

@ -90,7 +90,8 @@ subtest 'Bumping thread', sub {
$t->get_ok('/thread/bump/1' )->status_is(200); $t->get_ok('/thread/bump/1' )->status_is(200);
$t->get_ok('/thread/bump/65536')->status_is(404); $t->get_ok('/thread/bump/65536')->status_is(404);
$t->get_ok('/thread/bump/1', form => {captcha => 'bump'})->status_is(400); $t->get_ok('/thread/bump/1', form => {captcha => 'bump'})->status_is(200);
$t->get_ok('/thread/bump/1', form => {captcha => 'aaaa'})->status_is(400);
}; };
subtest 'Flagging thread', sub { subtest 'Flagging thread', sub {
@ -104,7 +105,8 @@ subtest 'Flagging thread', sub {
$t->get_ok('/thread/flag/1' )->status_is(200); $t->get_ok('/thread/flag/1' )->status_is(200);
$t->get_ok('/thread/flag/65536')->status_is(404); $t->get_ok('/thread/flag/65536')->status_is(404);
$t->get_ok('/thread/flag/1', form => {captcha => 'flag'})->status_is(400); $t->get_ok('/thread/flag/1', form => {captcha => 'flag'})->status_is(200);
$t->get_ok('/thread/flag/1', form => {captcha => 'aaaa'})->status_is(400);
}; };
done_testing; done_testing;

View File

@ -0,0 +1,17 @@
% layout 'default';
% title $remark_id ? "Flag Remark #$remark_id" : '?';
<h2 class="page-title"><%= title %></h2>
<% if ($remark_id) { =%>
<form class="form-body">
<div class="form-field">
<% if (my $error = validation->error('captcha')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for captcha => "Enter the word 'flag' to confirm:" %>
<%= text_field captcha => id => 'captcha' %>
</div>
<button type="submit" class="form-button">Confirm</button>
</fieldset>
</form>
<% } =%>