X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FSubmit.pm;h=b08399e005d4f74e0b666aceafcee0e0decb39d1;hb=1053baeebc541fc3508aabb6121759bb4a884e23;hp=7e4d1634d27ca6ef328cc530b4e095db02c4a976;hpb=2b0036ac8e077cc20cf9db6ff8dad4091ab50cb3;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Submit.pm b/lib/Gruntmaster/Page/Submit.pm index 7e4d163..b08399e 100644 --- a/lib/Gruntmaster/Page/Submit.pm +++ b/lib/Gruntmaster/Page/Submit.pm @@ -3,46 +3,64 @@ package Gruntmaster::Page::Submit; use 5.014000; use strict; use warnings; -use parent qw/Exporter/; -our @EXPORT_OK = qw/generate/; +use Gruntmaster::Page::Base; +our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant FORMATS => [qw/CPP/]; +use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/; +use File::Slurp qw/read_file/; +use Plack::Request; -use HTML::Template::Compiled; -use Gruntmaster::Page::Common qw/cook_templates reload_templates/; -use Gruntmaster::Data qw/problem_name problems/; +use constant FORMAT_EXTENSION => { + C => 'c', + CPP => 'cpp', + MONO => 'cs', + JAVA => 'java', + PASCAL => 'pas', + PERL => 'pl', + PYTHON => 'py', +}; -my %orig_templates = ( - en => <<'HTML', -
-

- -

+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 if $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}, + ); -my %templates = cook_templates %orig_templates, submit => 'Submit job'; + set_job_inmeta $job, { + files => { + prog => { + format => $format, + name => 'prog.' . FORMAT_EXTENSION->{$format}, + content => $prog, + } + } + }; -sub generate{ - %templates = cook_templates %orig_templates, submit => 'Submit job' if reload_templates; - - my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); - my @problems = map +{ id => $_, name => problem_name }, problems; - $htc->param(problems => \@problems); - $htc->param(formats => FORMATS); - $htc->output + $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