Basic input validation

This commit is contained in:
swaggboi 2022-08-06 02:26:53 -04:00
parent 48de91f31b
commit 705a136690
2 changed files with 14 additions and 6 deletions

View File

@ -44,12 +44,21 @@ get '/view', sub ($c) {
# Post
any [qw{GET POST}], '/post', sub ($c) {
my $thread_author = $c->param('name' );
my $thread_title = $c->param('title');
my $thread_body = $c->param('post' );
my $v;
if ($thread_author && $thread_title && $thread_body) {
$c->thread->create_thread($thread_author, $thread_title, $thread_body);
$v = $c->validation() if $c->req->method eq 'POST';
if ($v && $v->has_data) {
my $thread_author = $c->param('name' ) || 'Anonymous';
my $thread_title = $c->param('title');
my $thread_body = $c->param('post' );
$v->required('name' )->size(1, 63 );
$v->required('title')->size(1, 127 );
$v->required('post' )->size(2, 4000);
$c->thread->create_thread($thread_author, $thread_title, $thread_body)
unless $v->has_error();
return $c->redirect_to('view');
}

View File

@ -26,5 +26,4 @@ Run the tests locally (against development environment)
1. Moar tests...
1. Pick a date format
1. Validate input
1. **Moar tests!!**