Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made login and new user pages.

New user page needs input validation.
  • Loading branch information...
commit 1e07ad99d2947a877aafd43c2d9215f862db16aa 1 parent 3c90c7c
David Barksdale authored
1  .gitignore
View
@@ -3,3 +3,4 @@ pom.xml
/lib/
/classes/
.lein-deps-sum
+.lein-failures
3  project.clj
View
@@ -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)
2  src/ctf_website/server.clj
View
@@ -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})))
14 src/ctf_website/views/home.clj
View
@@ -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"}]]]))
14 src/ctf_website/views/login.clj
View
@@ -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"]))))
37 src/ctf_website/views/new.clj
View
@@ -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)])))))
Please sign in to comment.
Something went wrong with that request. Please try again.