From: Marius Gavrilescu Date: Wed, 5 Feb 2014 22:39:54 +0000 (+0200) Subject: Add submit X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=8d29b3b10314c58d01fe2ce7e69865d04525406d;p=gruntmaster-page.git Add submit --- diff --git a/app.psgi b/app.psgi index f13ef8e..50ec1a9 100644 --- a/app.psgi +++ b/app.psgi @@ -8,7 +8,8 @@ use Plack::Request; sub some_auth_required { my $r = Plack::Request->new($_[0]); - return 1 if $r->path eq '/action/passwd'; + my $word = qr,(\w+),a; + return 1 if $r->path eq '/action/passwd' || $r->path =~ m,/pb/$word/submit$,; 0 } diff --git a/lib/Gruntmaster/Page/Passwd.pm b/lib/Gruntmaster/Page/Passwd.pm index 4604fbc..86689ac 100644 --- a/lib/Gruntmaster/Page/Passwd.pm +++ b/lib/Gruntmaster/Page/Passwd.pm @@ -11,7 +11,7 @@ use Apache2::Authen::Passphrase qw/pwcheck pwset/; use Plack::Request; sub generate{ - my ($self, $format, $env, $ct, $job, $ext) = @_; + my ($self, $format, $env) = @_; my $r = Plack::Request->new($env); my ($oldpass, $newpass, $confirm) = map {scalar $r->param($_)} 'password', 'new_password', 'confirm_new_password'; diff --git a/lib/Gruntmaster/Page/Pb/Entry.pm b/lib/Gruntmaster/Page/Pb/Entry.pm index 4eacd4e..2672769 100644 --- a/lib/Gruntmaster/Page/Pb/Entry.pm +++ b/lib/Gruntmaster/Page/Pb/Entry.pm @@ -15,18 +15,18 @@ use constant TEMPLATES => {
-
+
Author
Owner

Submit solution

-
+ -
+
- -

+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 diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 66f86fe..1fc3a85 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -70,9 +70,9 @@ BEGIN{ get qr,$ct/log/st, => 'St'; get qr,$ct/log/job/$word, => 'Log::Entry'; get qr,$ct/log/src/$word\.$word, => 'Src'; - get qr,$ct/submit, => 'Submit'; get qr,$ct/pb/, => 'Pb'; get qr,$ct/pb/$word, => 'Pb::Entry'; + post qr,$ct/pb/$word/submit, => 'Submit'; post qr,/action/register, => 'Register'; post qr,/action/passwd, => 'Passwd';