diff options
author | joanofarctangent@gmail.com <iduffe@dev.piny.svcs.cs.pdx.edu> | 2011-01-18 19:47:16 -0800 |
---|---|---|
committer | joanofarctangent@gmail.com <iduffe@dev.piny.svcs.cs.pdx.edu> | 2011-01-18 19:47:16 -0800 |
commit | 419dcb3367ee77ec47c0c048df8bc3f3a0f26c7b (patch) | |
tree | 92c64c2e5ec43d5d17e2a81c87a817d57c090975 /pinyweb | |
parent | 48c2276609a321b08df6e9ced23a30460cae1cb9 (diff) | |
parent | eb8dc87dca8089bfccaed79db0ed3b5483054472 (diff) | |
download | piny-code-419dcb3367ee77ec47c0c048df8bc3f3a0f26c7b.tar.gz piny-code-419dcb3367ee77ec47c0c048df8bc3f3a0f26c7b.zip |
Merge branch 'master' of piny.be:/srv/git/piny-code
Diffstat (limited to 'pinyweb')
-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 } ); + }; + }; }; |