From ec82ffae25be5bf6454840c4b15ac446f1c5c04a Mon Sep 17 00:00:00 2001 From: swaggboi Date: Sat, 5 Aug 2023 03:14:09 -0400 Subject: [PATCH] Add some stuff before I pass out --- lib/PostText.pm | 37 ++++++++++++++++++++++++--------- lib/PostText/Controller/Page.pm | 2 ++ templates/page/captcha.html.ep | 29 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 templates/page/captcha.html.ep diff --git a/lib/PostText.pm b/lib/PostText.pm index 923cdae..ef4bf4d 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -3,6 +3,7 @@ package PostText; # Sep 22 2022 use Mojo::Base 'Mojolicious', -signatures; +use Mojo::Util qw{b64_encode gzip}; use Mojo::Pg; use Crypt::Passphrase; use Text::Markdown qw{markdown}; @@ -109,6 +110,16 @@ sub startup($self) { 1; }); + # For CAPTCHA protected routes + my $human = $r->under('/human', sub ($c) { + return 1 if $c->session('is_human'); + + return $c->redirect_to( + captcha_page => return_url => + b64_encode gzip $c->url_for->to_abs->to_string + ), undef; + }); + # Root redirect $r->get('/', sub ($c) { $c->redirect_to('threads_list') }); @@ -124,8 +135,13 @@ sub startup($self) { $r->get('/rules')->to('page#rules')->name('rules_page'); + $r->get('/captcha/:return_url') + ->to('page#captcha') + ->name('captcha_page'); + # Thread - my $thread = $r->any('/thread'); + my $thread = $r ->any('/thread'); + my $human_thread = $human->any('/thread'); $thread->get('/list/:list_page', [list_page => qr/\d+/], {list_page => 1}) ->to('thread#by_page') @@ -141,20 +157,21 @@ sub startup($self) { ->to('thread#by_id') ->name('single_thread'); - $thread->get('/bump/:thread_id', [thread_id => qr/\d+/]) - ->to('thread#bump') - ->name('bump_thread'); - - $thread->get('/flag/:thread_id', [thread_id => qr/\d+/]) - ->to('thread#flag') - ->name('flag_thread'); - $thread->get('feed', [format => [qw{rss xml}]]) ->to('thread#feed') ->name('threads_feed'); + $human_thread->get('/bump/:thread_id', [thread_id => qr/\d+/]) + ->to('thread#bump') + ->name('bump_thread'); + + $human_thread->get('/flag/:thread_id', [thread_id => qr/\d+/]) + ->to('thread#flag') + ->name('flag_thread'); + # Remark - my $remark = $r->any('/remark'); + my $remark = $r ->any('/remark'); + my $human_remark = $human->any('/remark'); $remark->any([qw{GET POST}], '/post/:thread_id', [thread_id => qr/\d+/]) ->any('/:remark_id', [remark_id => qr/\d+/], {remark_id => 0}) diff --git a/lib/PostText/Controller/Page.pm b/lib/PostText/Controller/Page.pm index 0958ecc..eb52046 100644 --- a/lib/PostText/Controller/Page.pm +++ b/lib/PostText/Controller/Page.pm @@ -6,4 +6,6 @@ sub about($self) { $self->render } sub rules($self) { $self->render } +sub captcha($self) { $self->render } + 'false'; diff --git a/templates/page/captcha.html.ep b/templates/page/captcha.html.ep new file mode 100644 index 0000000..4c55326 --- /dev/null +++ b/templates/page/captcha.html.ep @@ -0,0 +1,29 @@ +% layout 'default'; +% title 'CAPTCHA'; +% content_for open_graph => begin + + + +% end +% content_for twitter_card => begin + + +% end +

<%= title %>

+
+
+ <% if (my $error = validation->error('answer')) { =%> +

Must be between <%= $error->[2] %> + and <%= $error->[3] %> characters.

+ <% } =%> + <%#= label_for answer => "What number is this?: $roman_number" %> + <%= text_field 'answer', ( + id => 'answer', + maxlength => 1, + minlength => 1, + required => undef + ) %> +
+ <%= hidden_field url => $return_url, id => 'url' %> + +