]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Submit.pm
Require a delay of 30 seconds between jobs from a single user
[gruntmaster-page.git] / lib / Gruntmaster / Page / Submit.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page::Submit;
2
3use 5.014000;
4use strict;
5use warnings;
8d29b3b1 6use Gruntmaster::Page::Base;
bb95f538 7our @ISA = qw/Gruntmaster::Page::Base/;
42546e6c
MG
8our $VERSION = '0.001';
9
8d29b3b1
MG
10use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/;
11use File::Slurp qw/read_file/;
12use Plack::Request;
42546e6c 13
8d29b3b1
MG
14use constant FORMAT_EXTENSION => {
15 C => 'c',
16 CPP => 'cpp',
17 MONO => 'cs',
18 JAVA => 'java',
19 PASCAL => 'pas',
20 PERL => 'pl',
21 PYTHON => 'py',
22};
42546e6c 23
8d29b3b1
MG
24sub generate{
25 my ($self, $frm, $env) = @_;
26 my $r = Plack::Request->new($env);
27 my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code';
28 my $upload = $r->upload('prog');
29 if (defined $upload) {
95a9ad1b 30 my $temp = read_file $upload->path;
8d29b3b1
MG
31 $prog = $temp if $temp
32 }
33 die if defined $contest && $contest !~ /^\w+$/ ;
34 die if defined $contest && (time > contest_end $contest);
35 return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog;
1acbe467
MG
36 return reply 'You must wait 30 seconds between jobs' unless time > lastjob ($r->user) + 30;
37 set_lastjob $r->user;
42546e6c 38
3c53f795 39 local $Gruntmaster::Data::contest = $contest if $contest;
42546e6c 40
8d29b3b1
MG
41 my $job = push_job (
42 date => time,
43 problem => $problem,
44 user => $r->user,
45 defined $private ? (private => $private) : (),
46 defined $contest ? (contest => $contest, private => 1) : (),
47 filesize => length $prog,
48 extension => FORMAT_EXTENSION->{$format},
49 );
42546e6c 50
8d29b3b1
MG
51 set_job_inmeta $job, {
52 files => {
53 prog => {
54 format => $format,
55 name => 'prog.' . FORMAT_EXTENSION->{$format},
56 content => $prog,
57 }
58 }
59 };
2b0036ac 60
8d29b3b1
MG
61 $contest //= '';
62 PUBLISH 'jobs', "$contest.$job";
63 [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']]
42546e6c
MG
64}
65
8d29b3b1
MG
66sub variants{ [[reply => 1, undef, undef, undef, undef, undef]] }
67
42546e6c 681
This page took 0.04909 seconds and 4 git commands to generate.