X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FSubmit.pm;h=096af4d81a2e9092a545e73a13b34c7c36b1d730;hb=8d29b3b10314c58d01fe2ce7e69865d04525406d;hp=344661b142ee74f0800b1e32d3f89594c1ed01d6;hpb=6af4c58414046030f387c7f8cb8aa06776d64607;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Submit.pm b/lib/Gruntmaster/Page/Submit.pm index 344661b..096af4d 100644 --- a/lib/Gruntmaster/Page/Submit.pm +++ b/lib/Gruntmaster/Page/Submit.pm @@ -3,38 +3,64 @@ package Gruntmaster::Page::Submit; use 5.014000; use strict; use warnings; -use Gruntmaster::Page::Base submit => 'Submit job'; +use Gruntmaster::Page::Base; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant FORMATS => [qw/C CPP JAVA PERL PYTHON/]; +use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/; +use File::Slurp qw/read_file/; +use Plack::Request; -use constant TEMPLATES => { - en => <<'HTML', -
-

+use constant FORMAT_EXTENSION => { + C => 'c', + CPP => 'cpp', + MONO => 'cs', + JAVA => 'java', + PASCAL => 'pas', + PERL => 'pl', + PYTHON => 'py', +}; -

+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'; + my $upload = $r->upload('prog'); + if (defined $upload) { + my $temp = read_file $upload->filename; + $prog = $temp if $temp + } + die if defined $contest && $contest !~ /^\w+$/ ; + die if defined $contest && (time > contest_end $contest); + return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog; -

+ local $Gruntmaster::Data::contest = $contest; - -HTML -}; + my $job = push_job ( + date => time, + problem => $problem, + user => $r->user, + defined $private ? (private => $private) : (), + defined $contest ? (contest => $contest, private => 1) : (), + filesize => length $prog, + extension => FORMAT_EXTENSION->{$format}, + ); -sub _generate{ - my ($self, $htc, $path, $lang) = @_; + set_job_inmeta $job, { + files => { + prog => { + format => $format, + name => 'prog.' . FORMAT_EXTENSION->{$format}, + content => $prog, + } + } + }; - my @problems = map +{ id => $_, name => problem_name }, problems; - $htc->param(problems => \@problems); - $htc->param(formats => FORMATS); + $contest //= ''; + PUBLISH 'jobs', "$contest.$job"; + [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']] } +sub variants{ [[reply => 1, undef, undef, undef, undef, undef]] } + 1