X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FGruntmaster.pm;h=7a3dc348b065037ae139a111b2494945a85eb747;hb=2beb67b456221a9a56d4354f0f4a5c435f0c3a73;hp=35d788e8887c7e5589c38ffd19d3b80d7fe66e06;hpb=8798626b0e96a4d1eb423f7f70ece78a2fcb4ae7;p=plack-app-gruntmaster.git diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 35d788e..7a3dc34 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -34,6 +34,7 @@ use constant CONTENT_TYPES => +{ pas => 'text/x-pascal', pl => 'text/x-perl', py => 'text/x-python', + rb => 'application/x-ruby', l => 'text/plain', }; @@ -48,6 +49,7 @@ use constant FORMAT_EXTENSION => { PASCAL => 'pas', PERL => 'pl', PYTHON => 'py', + RUBY => 'rb', SBCL => 'l', }; @@ -107,18 +109,6 @@ sub dispatch_request{ [200, \@headers, [job->source]] }, - sub (?:contest=) { - return NOT_FOUND if !contest; - forbid contest->is_pending; - response_filter { return shift } - }, - - sub (?:problem=) { - return NOT_FOUND if !problem; - forbid problem->is_private; - response_filter { return shift } - }, - sub (?:format~) { my $format = lc ($_{format} // ''); response_filter { @@ -150,22 +140,21 @@ sub dispatch_request{ sub (/login) { forbid !remote_user; - - my $return = $env->{HTTP_REFERER} // '/'; - [303, ['Set-Cookie' => "username=".remote_user->id, Location => $return], []] + [200, ['Content-Type' => 'text/plain; charset=UTF-8', 'Cache-Control' => 'private, max-age=300', Vary => 'Authorization'], [$env->{REMOTE_USER}]] }, sub (/ct/:contest/log/st) { redirect "/st/$_{contest}" }, sub (/us/) { response us => 'Users', {us => db->user_list} }, sub (/ct/ + ?:owner~) { response ct => 'Contests', db->contest_list(%_) }, - sub (/log/ + ?:contest~&:owner~&:page~&:problem~&:private~) { + sub (/log/ + ?:contest~&:owner~&:page~&:problem~&:private~&:result~) { forbid $_{private}; response log => 'Job list', {%{db->job_list(%_)}, maybe contest => $_{contest},} }, sub (/pb/ + ?:owner~&:contest~&:private~) { forbid $_{private}; - response pb => 'Problems', {%{db->problem_list(%_)}, maybe contest => $_{contest}} + forbid contest && contest->is_pending; + response pb => 'Problems', db->problem_list(%_) }, sub (/us/:user) { response us_entry => user->name, db->user_entry($_{user}) }, @@ -177,16 +166,17 @@ sub dispatch_request{ sub (/pb/:problem + ?contest~) { my (undef, undef, $contest) = @_; $_{contest} = $contest; - return NOT_FOUND if !contest && !problem->is_in_archive || contest && !db->contest_problems->find($_{contest}, $_{problem}); - forbid problem->is_private; - if (contest && contest->is_running) { + return NOT_FOUND if contest && !db->contest_problems->find($_{contest}, $_{problem}); + forbid problem->private && !contest; + if (contest) { + return redirect "/pb/$_{problem}" unless contest->is_running; forbid !remote_user; $privacy = 'private'; } response pb_entry => problem->name, {%{db->problem_entry($_{problem}, $_{contest}, remote_user && remote_user->id)}, maybe contest => $_{contest}}; }, sub (/sol/:problem) { - forbid !problem->is_in_archive; + forbid problem->private; response sol => 'Solution of ' . problem->name, {solution => db->problem($_{problem})->solution}; }, @@ -199,17 +189,17 @@ sub dispatch_request{ sub (/action/submit + %:problem=&:contest~&:prog_format=&:source_code~ + *prog~) { my (undef, undef, $prog) = @_; forbid !remote_user; + my $private = (problem->private && !contest) ? 1 : 0; return reply 'This contest has finished' if contest && contest->is_finished; - return reply 'This contest has not yet started' if !admin && contest && contest->is_pending; - return reply 'This problem does not belong to this contest' if !contest && !problem->is_in_archive || contest && !db->contest_problems->find($_{contest}, $_{problem}); + return reply 'This contest has not yet started' if contest && contest->is_pending; + return reply 'This problem is private' if !admin && $private; + return reply 'This problem does not belong to this contest' if contest && !db->contest_problems->find($_{contest}, $_{problem}); return reply 'Maximum source size is 10KB' if ($prog ? $prog->size : length $_{source_code}) > 10 * 1024; return reply 'You must wait 30 seconds between jobs' if !admin && time <= remote_user->lastjob + 30; remote_user->update({lastjob => time}); my $source = $prog ? read_file $prog->path : $_{source_code}; unlink $prog->path if $prog; - my $private = (problem->private && !$_{contest}) ? 1 : 0; - $private = 1 if contest && contest->is_pending; my $newjob = db->jobs->create({ maybe contest => $_{contest}, private => $private,