diff options
-rwxr-xr-x | pinyweb/cgi-bin/checkconstraint.cgi | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/pinyweb/cgi-bin/checkconstraint.cgi b/pinyweb/cgi-bin/checkconstraint.cgi index 8db0903..757bcaa 100755 --- a/pinyweb/cgi-bin/checkconstraint.cgi +++ b/pinyweb/cgi-bin/checkconstraint.cgi @@ -11,29 +11,35 @@ use Piny; my $q = CGI->new( ); -my $type = $q->param( 't' ); -my $value = $q->param( 'v' ); - -if ( not defined $type or not defined $value ) { - print "Status: 400 Bad Request\nContent-type: application/json\n\n"; - print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Required parameter missing." } ); +if ( $q->request_method( ) eq "OPTIONS" ) { + print "Status: 204 No Content\nAccess-Control-Allow-Origin: *\n\n"; } else { - my $constraint = find_type_constraint( $type ); + my $type = $q->param( 't' ); + my $value = $q->param( 'v' ); - if ( not defined $constraint ) { + if ( not defined $type or not defined $value ) { print "Status: 400 Bad Request\nContent-type: application/json\n\n"; - print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Invalid constraint name." } ); + print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Required parameter missing." } ); } else { - print "Status: 200 OK\nContent-type: application/json\n\n"; - - my $error = $constraint->validate( $value ); + my $constraint = find_type_constraint( $type ); - if ( defined $error ) { - print encode_json( { "ok" => JSON::false, "msg" => $error } ); + if ( not defined $constraint ) { + print "Status: 400 Bad Request\nContent-type: application/json\n\n"; + print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Invalid constraint name." } ); } else { - print encode_json( { "ok" => JSON::true } ); + + print "Status: 200 OK\nContent-type: application/json\n\n"; + + my $error = $constraint->validate( $value ); + + if ( defined $error ) { + print encode_json( { "ok" => JSON::false, "msg" => $error } ); + } else { + print encode_json( { "ok" => JSON::true } ); + }; + }; }; |