Add registration page and mechanism for OpenCL contest.
authorMarc Burns <m4burns@uwaterloo.ca>
Wed, 15 Feb 2012 21:08:01 +0000 (16:08 -0500)
committerMarc Burns <m4burns@uwaterloo.ca>
Wed, 15 Feb 2012 21:08:01 +0000 (16:08 -0500)
opencl/.htaccess [new file with mode: 0644]
opencl/Makefile
opencl/register-fail.xml [new file with mode: 0644]
opencl/register-success.xml [new file with mode: 0644]
opencl/register.cgi [new file with mode: 0755]
opencl/register.xml

diff --git a/opencl/.htaccess b/opencl/.htaccess
new file mode 100644 (file)
index 0000000..62e7e7f
--- /dev/null
@@ -0,0 +1,2 @@
+AddHandler cgi-script .cgi
+Options +Indexes +ExecCGI
index c9450fa..aa55fa0 100644 (file)
@@ -1,3 +1,3 @@
-FILES = index.html register.html
+FILES = index.html register.html register-fail.html register-success.html register.cgi .htaccess
 RELDIR = opencl/
 include ../common.mk
diff --git a/opencl/register-fail.xml b/opencl/register-fail.xml
new file mode 100644 (file)
index 0000000..17ee20f
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version='1.0'?>
+
+<!DOCTYPE cscpage SYSTEM "../csc.dtd">
+
+<cscpage title="CSC/AMD OpenCL Competition Registration">
+ <header />
+ <section title="CSC/AMD OpenCL Competition Registration"> 
+  <p>
+
+  You didn't fill out all required information on the registration form. Please <a href="register">try again</a>.
+
+  </p>
+ </section>
+
+ <footer />
+</cscpage>
diff --git a/opencl/register-success.xml b/opencl/register-success.xml
new file mode 100644 (file)
index 0000000..fbea588
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version='1.0'?>
+
+<!DOCTYPE cscpage SYSTEM "../csc.dtd">
+
+<cscpage title="CSC/AMD OpenCL Competition Registration">
+ <header />
+ <section title="CSC/AMD OpenCL Competition Registration"> 
+  <p>
+
+  Thank you for registering to participate. Your information has been recorded, and we will be contacting you shortly with further instructions.
+
+  </p>
+ </section>
+
+ <footer />
+</cscpage>
diff --git a/opencl/register.cgi b/opencl/register.cgi
new file mode 100755 (executable)
index 0000000..5e14125
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env racket
+#lang racket
+(require srfi/98)
+(require net/uri-codec)
+(require net/smtp)
+
+(define ERROR-HEADER "Location: http://csclub.uwaterloo.ca/opencl/register-fail\n\n")
+(define SUCCESS-HEADER "Location: http://csclub.uwaterloo.ca/opencl/register-success\n\n")
+
+(define (is-user? str) (equal? (list str) (regexp-match #rx"[A-Za-z0-9._]+" str)))
+(define (is-email? str) (equal? (list str) (regexp-match #rx"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+" str)))
+
+(define required-fields `( (quest . ,is-user?) (email . ,is-email?)))
+(define check-fields '(team open closed))
+
+(define (identity x) x)
+
+(let*
+  ((post-data (form-urlencoded->alist (port->string)))
+   (required-extract
+     (map
+       (lambda(x) (let ((e (assoc (car x) post-data)))
+                       (cond [(false? e) #f]
+                             [((cdr x) (cdr e)) e]
+                             [else #f])))
+       required-fields))
+   (check-extract (filter identity (map ((curryr assoc) post-data) check-fields)))
+   (filled-out? (andmap identity required-extract)))
+  (when (not filled-out?)
+    (printf ERROR-HEADER)
+    (exit 0))
+  (smtp-send-message
+    "caffeine.csclub.uwaterloo.ca"
+    "opencl-contest-registration@csclub"
+    (list "init512@gmail.com")
+    "Subject: Contestant registered!\n\n"
+    (list (with-output-to-string
+      (lambda() (write (append required-extract check-extract))))))
+  (printf SUCCESS-HEADER)
+  (exit 0))
+
index 8bd5838..9d78129 100644 (file)
@@ -7,7 +7,28 @@
  
  <section title="CSC/AMD OpenCL Competition Registration"> 
   <p>
-  Registration will open on the 16th of February.
+
+  <form action="register.cgi" method="post">
+    <table cellpadding="5px">
+    <tr>
+      <td>Quest ID:</td><td><input type="text" name="quest" /></td>
+    </tr>
+    <tr>
+      <td>Email:</td><td><input type="text" name="email" /></td>
+    </tr>
+    <tr>
+      <td>Are you participating with a team?</td><td><input type="checkbox" name="team" value="yes" /></td>
+    </tr>
+    <tr>
+      <td>Problem type:</td><td><input type="checkbox" name="open" value="yes" /> Open Submission
+                                <input type="checkbox" name="closed" value="yes" /> Problem Set</td>
+    </tr>
+    <tr>
+      <td></td><td><input type="submit" name="Register" value="Register" /></td>
+    </tr>
+    </table>
+  </form>
+
   </p>
  </section>