diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2012-04-03 23:52:00 -0500 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2012-04-03 23:52:00 -0500 |
commit | 1e07ad99d2947a877aafd43c2d9215f862db16aa (patch) | |
tree | df21af266829e1f323b7da11ca498fdde8d3a6ba | |
parent | 3c90c7c642a20f0389b43a3867b9c26c53aabc77 (diff) |
Made login and new user pages.
New user page needs input validation.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | project.clj | 3 | ||||
-rw-r--r-- | src/ctf_website/server.clj | 2 | ||||
-rw-r--r-- | src/ctf_website/views/home.clj | 14 | ||||
-rw-r--r-- | src/ctf_website/views/login.clj | 14 | ||||
-rw-r--r-- | src/ctf_website/views/new.clj | 37 |
6 files changed, 68 insertions, 3 deletions
@@ -3,3 +3,4 @@ pom.xml /lib/ /classes/ .lein-deps-sum +.lein-failures diff --git a/project.clj b/project.clj index 6f93443..a99efe2 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,7 @@ (defproject ctf-website "0.1.0-SNAPSHOT" :description "FIXME: write this!" :dependencies [[org.clojure/clojure "1.3.0"] - [noir "1.2.1"]] + [noir "1.2.1"] + [net.sf.jpam/jpam "1.1"]] :main ctf-website.server) diff --git a/src/ctf_website/server.clj b/src/ctf_website/server.clj index d6dd776..876e836 100644 --- a/src/ctf_website/server.clj +++ b/src/ctf_website/server.clj @@ -5,7 +5,7 @@ (defn -main [& m] (let [mode (keyword (or (first m) :dev)) - port (Integer. (get (System/getenv) "PORT" "8080"))] + port (Integer. (get (System/getenv) "PORT" "80"))] (server/start port {:mode mode :ns 'ctf-website}))) diff --git a/src/ctf_website/views/home.clj b/src/ctf_website/views/home.clj index fe71e36..f2aabb4 100644 --- a/src/ctf_website/views/home.clj +++ b/src/ctf_website/views/home.clj @@ -5,4 +5,16 @@ (defpage "/" [] (common/layout - [:p "Welcome to ctf-website"])) + [:h1 "Austin 2600 CTF server"] + [:a {:href "new"} "Create account"] + [:form {:method "POST" + :action "login"} + [:p "Username:" + [:input {:type "text" + :name "username"}]] + [:p "Password:" + [:input {:type "password" + :name "password"}]] + [:p + [:input {:type "submit" + :value "Login"}]]])) diff --git a/src/ctf_website/views/login.clj b/src/ctf_website/views/login.clj new file mode 100644 index 0000000..50aae1b --- /dev/null +++ b/src/ctf_website/views/login.clj @@ -0,0 +1,14 @@ +(ns ctf-website.views.login + (:require [ctf-website.views.common :as common]) + (:import net.sf.jpam.Pam) + (:use [noir.core :only [defpage]] + [hiccup.core :only [html]])) + +(defpage [:post "/login"] {:keys [username password]} + (let [pam (Pam.) + authenticated (.authenticateSuccessful pam username password)] + (if authenticated + (common/layout + [:p "You're in"]) + (common/layout + [:p "Go away"])))) diff --git a/src/ctf_website/views/new.clj b/src/ctf_website/views/new.clj new file mode 100644 index 0000000..70da5c7 --- /dev/null +++ b/src/ctf_website/views/new.clj @@ -0,0 +1,37 @@ +(ns ctf-website.views.new + (:require [ctf-website.views.common :as common]) + (:import java.lang.ProcessBuilder) + (:use [noir.core :only [defpage]] + [hiccup.core :only [html]])) + +(defpage + "/new" [] + (common/layout + [:form {:method "POST" + :action "new"} + [:p "Username:" + [:input {:type "text" + :name "username"}]] + [:p "Password:" + [:input {:type "password" + :name "password"}]] + [:p + [:input {:type "submit" + :value "Create"}]]])) + +(defpage + [:post "/new"] {:keys [username password]} + (let [adduser (.start (ProcessBuilder. (list "adduser" username))) + _ (.close (.getOutputStream adduser)) + retval (.waitFor adduser)] + (if (not (= 0 retval)) + (common/layout + [:p "Try a username that doesn't suck"] + [:p (str "result: " retval)]) + (let [chpasswd (.start (ProcessBuilder. (list "chpasswd"))) + out (.getOutputStream chpasswd) + _ (.write out (.getBytes (str username ":" password) "UTF-8")) + _ (.close out) + retval (.waitFor chpasswd)] + (common/layout + [:p (str "result: " retval)]))))) |