]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Submit.pm
Fix redirect after submit
[gruntmaster-page.git] / lib / Gruntmaster / Page / Submit.pm
index b08399e005d4f74e0b666aceafcee0e0decb39d1..0c42de9ff1252058018c527be1702d5ff54c235e 100644 (file)
@@ -1,15 +1,6 @@
 package Gruntmaster::Page::Submit;
 
-use 5.014000;
-use strict;
-use warnings;
 use Gruntmaster::Page::Base;
-our @ISA = qw/Gruntmaster::Page::Base/;
-our $VERSION = '0.001';
-
-use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/;
-use File::Slurp qw/read_file/;
-use Plack::Request;
 
 use constant FORMAT_EXTENSION => {
        C => 'c',
@@ -25,42 +16,34 @@ sub generate{
        my ($self, $frm, $env) = @_;
        my $r = Plack::Request->new($env);
        my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code';
+       $problem //= $env->{'gruntmaster.problem'};
+       $contest //= $env->{'gruntmaster.contest'};
        my $upload = $r->upload('prog');
        if (defined $upload) {
-               my $temp = read_file $upload->filename;
+               my $temp = read_file $upload->path;
                $prog = $temp if $temp
        }
        die if defined $contest && $contest !~ /^\w+$/ ;
-       die if defined $contest && (time > contest_end $contest);
+       die if defined $contest && (time > db($env)->contest($contest)->stop);
        return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog;
+       return reply 'Maximum source size is 10KB' if length $prog > 25 * 1024;
+       return reply 'You must wait 30 seconds between jobs' unless time > db($env)->user($r->user)->lastjob + 30;
+       db($env)->user($r->user)->update({lastjob => time});
 
-       local $Gruntmaster::Data::contest = $contest if $contest;
-
-       my $job = push_job (
+       db($env)->jobs->create({
+               defined $contest ? (contest => $contest) : (),
                date => time,
-               problem => $problem,
-               user => $r->user,
-               defined $private ? (private => $private) : (),
-               defined $contest ? (contest => $contest, private => 1) : (),
-               filesize => length $prog,
                extension => FORMAT_EXTENSION->{$format},
-       );
-
-       set_job_inmeta $job, {
-               files => {
-                       prog => {
-                               format => $format,
-                               name => 'prog.' . FORMAT_EXTENSION->{$format},
-                               content => $prog,
-                       }
-               }
-       };
+               format => $format,
+               defined $private ? (private => $private) : (),
+               problem => $problem,
+               source => $prog,
+               owner => $r->user
+       });
 
        $contest //= '';
-       PUBLISH 'jobs', "$contest.$job";
-       [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']]
+       #PUBLISH 'jobs', "$contest.$job";
+       [303, [Location => ($contest ? "/ct/$contest/log/" : '/log/')], ['']]
 }
 
-sub variants{ [[reply => 1, undef, undef, undef, undef, undef]] }
-
 1
This page took 0.023879 seconds and 4 git commands to generate.