Confirmation for bump_thread

This commit is contained in:
swagg boi 2023-06-13 20:22:07 -04:00
parent ce6d405b1d
commit f4c9d25139
4 changed files with 39 additions and 6 deletions

View file

@ -140,13 +140,24 @@ sub feed($self) {
sub bump($self) {
my $thread_id = $self->param('thread_id');
my $v = $self->validation;
$v->optional(captcha => 'trim')->size(4, 4)->like(qr/bump/i);
if ($v->is_valid) {
my $redirect_url =
$self->url_for('threads_list')->fragment('info')->to_abs;
$self->thread->bump($thread_id);
$self->flash(info => "Thread #$thread_id has been bumped. 🔝");
$self->redirect_to(
$self->url_for('threads_list')->fragment('info')->to_abs
);
return $self->redirect_to($redirect_url);
}
elsif ($v->has_error) {
$self->stash(status => 400)
}
$self->render;
}
sub flag($self) {

View file

@ -87,6 +87,10 @@ subtest 'Bumping thread', sub {
$t->get_ok('/thread/bump/1')->status_is(200)
->element_exists('p[class="stash-with-info"]')
->text_like(p => qr/Thread #1 has been bumped/);
$t->get_ok('/thread/bump/1' )->status_is(200);
$t->get_ok('/thread/bump/65536')->status_is(404);
$t->get_ok('/thread/bump/1', form => {captcha => 'bump'})->status_is(400);
};
subtest 'Flagging thread', sub {
@ -100,6 +104,7 @@ subtest 'Flagging thread', sub {
$t->get_ok('/thread/flag/1' )->status_is(200);
$t->get_ok('/thread/flag/65536')->status_is(404);
$t->get_ok('/thread/flag/1', form => {captcha => 'flag'})->status_is(400);
};
done_testing;

View file

@ -0,0 +1,17 @@
% layout 'default';
% title $thread_id ? "Bump Thread #$thread_id" : '?';
<h2 class="page-title"><%= title %></h2>
<% if ($thread_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 'bump' to confirm:" %>
<%= text_field captcha => id => 'captcha' %>
</div>
<button type="submit" class="form-button">Confirm</button>
</fieldset>
</form>
<% } =%>

View file

@ -11,7 +11,7 @@
<%= label_for captcha => "Enter the word 'flag' to confirm:" %>
<%= text_field captcha => id => 'captcha' %>
</div>
<button type="submit" class="form-button">Flag</button>
<button type="submit" class="form-button">Confirm</button>
</fieldset>
</form>
<% } =%>