improved error detection

This commit is contained in:
Rudis Muiznieks 2020-07-19 09:46:28 -05:00
parent 0ab5c509d9
commit 17b3c309fe
1 changed files with 4 additions and 4 deletions

View File

@ -195,7 +195,7 @@ EOF
if (defined $user && $user->{'verified'}) { if (defined $user && $user->{'verified'}) {
print_json_response($cgi, 400, {error => 'User already exists.'}); print_json_response($cgi, 400, {error => 'User already exists.'});
} elsif (defined $user && defined $user->{'pw_token_expires'} && $user->{'pw_token_expires'} >= time) { } elsif (defined $user && defined $user->{'pw_token_expires'} && $user->{'pw_token_expires'} >= time) {
print_json_response($cgi, 429, {error => "Please wait up to $pw_token_expiration_minutes minutes and try again."}); print_json_response($cgi, 429, {error => "Wait $pw_token_expiration_minutes minutes between this type of request."});
} else { } else {
my $password = util_json_body($cgi)->{'password'}; my $password = util_json_body($cgi)->{'password'};
if (!defined $password || length($password) < $minimum_password_length) { if (!defined $password || length($password) < $minimum_password_length) {
@ -330,7 +330,7 @@ EOF
print_response($cgi, 401, $not_authorized); print_response($cgi, 401, $not_authorized);
} elsif (length($plan) > $maximum_plan_length) { } elsif (length($plan) > $maximum_plan_length) {
print_json_response($cgi, 400, {error => "Plan exceeds maximum length of $maximum_plan_length."}); print_json_response($cgi, 400, {error => "Plan exceeds maximum length of $maximum_plan_length."});
} elsif (length($signature) > $maximum_signature_length) { } elsif (defined $signature && length($signature) > $maximum_signature_length) {
print_json_response($cgi, 400, {error => "Signature exceeds maximum length of $maximum_signature_length."}); print_json_response($cgi, 400, {error => "Signature exceeds maximum length of $maximum_signature_length."});
} else { } else {
util_save_plan($email, $plan, $signature); util_save_plan($email, $plan, $signature);
@ -535,7 +535,7 @@ EOF
my $basename = "$plan_dir/" . shell_quote($email); my $basename = "$plan_dir/" . shell_quote($email);
if (defined $plan) { if (defined $plan) {
open(my $plan_file, '>', "$basename.plan"); open(my $plan_file, '>', "$basename.plan") or die $!;
flock($plan_file, LOCK_EX); flock($plan_file, LOCK_EX);
print $plan_file $plan; print $plan_file $plan;
close($plan_file); close($plan_file);
@ -544,7 +544,7 @@ EOF
} }
if (defined $plan && defined $signature) { if (defined $plan && defined $signature) {
open(my $sig_file, '>', "$basename.asc"); open(my $sig_file, '>', "$basename.asc") or die $!;
flock($sig_file, LOCK_EX); flock($sig_file, LOCK_EX);
print $sig_file $signature; print $sig_file $signature;
close($sig_file); close($sig_file);