Fixed up errors for validation; validate moar; style errors

This commit is contained in:
swagg boi 2023-05-28 00:42:07 -04:00
parent b1583bbb95
commit 65bb0ef5a0
18 changed files with 101 additions and 44 deletions

View file

@ -58,11 +58,9 @@ Run the tests locally (against development environment):
## TODOs
1. Create mod takes null input??
1. Check status for items not found, should be 404 but getting 5xx
1. Report 404s better (thread by id and remark by id)
1. "All new posts flagged" mode (require approval for new posts)
1. Tests for mod-only user?
1. Check input validation
## Crazy future ideas

View file

@ -7,7 +7,7 @@
--true-gray: #999999;
--highlight-green: green;
--highlight-red: red;
--transparent: #FFFFFFDD;
--transparent: #FFFFFFBB;
box-sizing: border-box;
font-size: calc(8px + 1vmin);

View file

@ -76,6 +76,7 @@
.form-field {
display: flex;
flex-flow: column;
gap: 0.25em;
}
.form-field > textarea {
@ -97,13 +98,18 @@
background-color: var(--dark-blue);
}
.field-with-info {
.field-with-error {
border: dashed var(--highlight-red);
padding: 0.5em 0.25em;
}
.stash-with-info {
border: dashed var(--highlight-green) 0.5em;
padding: 1em;
background-color: var(--transparent);
}
.field-with-error {
.stash-with-error {
border: dashed var(--highlight-red) 0.5em;
padding: 1em;
background-color: var(--transparent);

View file

@ -37,8 +37,8 @@ sub login($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('email' );
$v->required('password');
$v->required('email' )->size(6, 320);
$v->required('password')->size(12, undef);
if ($v->has_error) {
$self->stash(status => 400)
@ -154,9 +154,9 @@ sub create($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('name' );
$v->required('email' );
$v->required('password');
$v->required('name' )->size(1, 64);
$v->required('email' )->size(6, 320);
$v->required('password')->size(12, undef);
if ($v->has_error) {
$self->stash(status => 400)
@ -182,8 +182,8 @@ sub admin_reset($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('email' );
$v->required('password');
$v->required('email' )->size(6, 320);
$v->required('password')->size(12, undef);
if ($v->has_error) {
$self->stash(status => 400)
@ -208,7 +208,7 @@ sub mod_reset($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('password');
$v->required('password')->size(12, undef);
if ($v->has_error) {
$self->stash(status => 400)
@ -235,7 +235,7 @@ sub lock_acct($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('email');
$v->required('email')->size(6, 320);
if ($v->has_error) {
$self->stash(status => 400)
@ -257,7 +257,7 @@ sub unlock_acct($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('email');
$v->required('email')->size(6, 320);
if ($v->has_error) {
$self->stash(status => 400)
@ -279,7 +279,7 @@ sub promote($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('email');
$v->required('email')->size(6, 320);
if ($v->has_error) {
$self->stash(status => 404)
@ -301,7 +301,7 @@ sub demote($self) {
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('email');
$v->required('email')->size(6, 320);
if ($v->has_error) {
$self->stash(status => 404)

View file

@ -11,7 +11,7 @@ my %valid_login = (
my %invalid_login = (
email => 'fuck@example.com',
password => 'ah fuck'
password => 'ah fuck goddamn'
);
subtest Login => sub {

View file

@ -40,7 +40,7 @@ subtest 'Post new remark', sub {
->text_like(h2 => qr/Thread #1/);
$t->post_ok('/remark/post/1', form => \%invalid_remark)->status_is(400)
->text_like(p => qr/Invalid text/);
->text_like(p => qr/Must be between/);
};
subtest 'Flagging remark', sub {
@ -49,7 +49,7 @@ subtest 'Flagging remark', sub {
->text_like(h2 => qr/Remark #1/);
$t->get_ok('/remark/flag/1')->status_is(200)
->element_exists('p[class="field-with-info"]')
->element_exists('p[class="stash-with-info"]')
->text_like(p => qr/Remark #1 has been flagged/);
};

View file

@ -66,10 +66,10 @@ subtest 'Post new thread', sub {
->text_like(h2 => qr/New Thread/);
$t->post_ok('/thread/post', form => \%invalid_title)->status_is(400)
->text_like(p => qr/Invalid title/);
->text_like(p => qr/Must be between/);
$t->post_ok('/thread/post', form => \%invalid_post)->status_is(400)
->text_like(p => qr/Invalid text/);
->text_like(p => qr/Must be between/);
$t->post_ok('/thread/post', form => \%valid_params)->status_is(200)
->text_like(h2 => qr/Thread #\d+/);
@ -85,7 +85,7 @@ subtest 'Bumping thread', sub {
->text_like(h2 => qr/Thread #1/);
$t->get_ok('/thread/bump/1')->status_is(200)
->element_exists('p[class="field-with-info"]')
->element_exists('p[class="stash-with-info"]')
->text_like(p => qr/Thread #1 has been bumped/);
};
@ -99,7 +99,7 @@ subtest 'Flagging thread', sub {
->text_like(h2 => qr/Thread #1/);
$t->get_ok('/thread/flag/1')->status_is(200)
->element_exists('p[class="field-with-info"]')
->element_exists('p[class="stash-with-info"]')
->text_like(p => qr/Thread #1 has been flagged/);
};

View file

@ -44,14 +44,14 @@
<% } =%>
</header>
<% if (flash 'error') { =%>
<p class="field-with-error" id="error"><%= flash 'error' %></p>
<p class="stash-with-error" id="error"><%= flash 'error' %></p>
<% } elsif (stash 'error') { =%>
<p class="field-with-error" id="error"><%= stash 'error' %></p>
<p class="stash-with-error" id="error"><%= stash 'error' %></p>
<% } =%>
<% if (flash 'info') { =%>
<p class="field-with-info" id="info"><%= flash 'info' %></p>
<p class="stash-with-info" id="info"><%= flash 'info' %></p>
<% } elsif (stash 'info') { =%>
<p class="field-with-info" id="info"><%= stash 'info' %></p>
<p class="stash-with-info" id="info"><%= stash 'info' %></p>
<% } =%>
<%= content =%>
<footer class="site-footer">

View file

@ -3,10 +3,18 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('email')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for email => 'Email' %>
<%= email_field email => (id => 'email') %>
</div>
<div class="form-field">
<% if (my $error = validation->error('password')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for password => 'Password' %>
<%= password_field password => (id => 'password') %>
</div>

View file

@ -3,14 +3,26 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('name')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for name => 'Name' %>
<%= text_field name => (id => 'name') %>
</div>
<div class="form-field">
<% if (my $error = validation->error('email')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for email => 'Email' %>
<%= email_field email => (id => 'email') %>
</div>
<div class="form-field">
<% if (my $error = validation->error('password')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for password => 'Password' %>
<%= password_field password => (id => 'password') %>
</div>

View file

@ -3,6 +3,10 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('email')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for email => 'Email' %>
<%= email_field email => (id => 'email') %>
</div>

View file

@ -3,6 +3,10 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('email')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for email => 'Email' %>
<%= email_field email => (id => 'email') %>
</div>

View file

@ -3,10 +3,18 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('email')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for email => 'Email' %>
<%= email_field email => (id => 'email') %>
</div>
<div class="form-field">
<% if (my $error = validation->error('password')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for password => 'Password' %>
<%= password_field password => (id => 'password') %>
</div>

View file

@ -3,6 +3,10 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('password')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for password => 'Password' %>
<%= password_field password => (id => 'password') %>
</div>

View file

@ -3,6 +3,10 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('email')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for email => 'Email' %>
<%= email_field email => (id => 'email') %>
</div>

View file

@ -3,6 +3,10 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('email')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for email => 'Email' %>
<%= email_field email => (id => 'email') %>
</div>

View file

@ -3,6 +3,10 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('author')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for author => 'Author' %>
<%= text_field author => session->{'author'}, (
id => 'author',
@ -10,11 +14,12 @@
minlength => 1,
required => undef
) %>
<% if (my $error = validation->error('author')) { =%>
<p class="field-with-error">Invalid author: 1 to 63 characters please.</p>
<% } =%>
</div>
<div class="form-field">
<% if (my $error = validation->error('body')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for body => 'Text' %>
<%= text_area body => (
id => 'body',
@ -24,9 +29,6 @@
rows => 6,
autofocus => undef
) %>
<% if (my $error = validation->error('body')) { =%>
<p class="field-with-error">Invalid text: Up to 4,000 characters only.</p>
<% } =%>
</div>
<button type="submit" class="form-button">Post</button>
</form>

View file

@ -3,6 +3,10 @@
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<div class="form-field">
<% if (my $error = validation->error('author')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for author => 'Author' %>
<%= text_field author => session->{'author'}, (
id => 'author',
@ -10,11 +14,12 @@
minlength => 1,
required => undef
) %>
<% if (my $error = validation->error('author')) { =%>
<p class="field-with-error">Invalid author: 1 to 63 characters please.</p>
<% } =%>
</div>
<div class="form-field">
<% if (my $error = validation->error('title')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for title => 'Title' %>
<%= text_field title => (
id => 'title',
@ -23,11 +28,12 @@
autofocus => undef,
required => undef
) %>
<% if (my $error = validation->error('title')) { =%>
<p class="field-with-error">Invalid title: 1 to 127 characters please.</p>
<% } =%>
</div>
<div class="form-field">
<% if (my $error = validation->error('body')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
and <%= $error->[3] %> characters.</p>
<% } =%>
<%= label_for body => 'Text' %>
<%= text_area body => (
id => 'body',
@ -36,9 +42,6 @@
required => undef,
rows => 6
) %>
<% if (my $error = validation->error('body')) { =%>
<p class="field-with-error">Invalid text: Up to 4,000 characters only.</p>
<% } =%>
</div>
<button type="submit" class="form-button">Post</button>
</form>