Basic input validation
This commit is contained in:
parent
48de91f31b
commit
705a136690
19
PostText.pl
19
PostText.pl
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue