diff options
-rw-r--r-- | cljssss-g.clj | 71 | ||||
-rw-r--r-- | login.st | 18 |
2 files changed, 54 insertions, 35 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj index ffb7ef2..f57275f 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -12,31 +12,6 @@ (def templates (new StringTemplateGroup "")) -(defservlet cljssss-g - (GET "/" - (if (@session :id) - (.toString - (doto (.getInstanceOf templates "index") - (.setAttributes {"title" "Subscriptions", - "mainParagraph" "Hi there!"}))) - (redirect-to "/login"))) - (GET "/login" - ;; FIXME - ) - (POST "/login" - (dosync - (with-db - (sql/with-query-results [{id :id password :password}] - ["SELECT id, password FROM user WHERE name = ?" - (@params :name)] - (if (= password (@params :password)) - (do - (alter session assoc :id id) - (redirect-to "/")) - (redirect-to "/login?valuesofbetawillgiverisetodom=true")))))) - (ANY "*" - (page-not-found))) - (def db-connection-data {:classname "org.sqlite.JDBC" :subprotocol "sqlite" :subname "cljssss-g.sqlite3" @@ -51,6 +26,40 @@ (sql/transaction ~@body))) +(defn login-view [] + (.toString (.getInstanceOf templates "login"))) + + +(defservlet cljssss-g + (GET "/login" + (if (= (params :valuesofbetawillgiverisetodom) "true") + (.toString (doto + (.getInstanceOf templates "login") + (.setAttributes {"logintext" "Login failed"}))) + (.toString (doto + (.getInstanceOf templates "login") + (.setAttributes {"logintext" "Login"}))))) + (POST "/login" + (dosync + (with-db + (sql/with-query-results [{id :id password :password}] + ["SELECT id, password FROM user WHERE name = ?" + (@params :name)] + (if (= password (@params :password)) + (do + (alter session assoc :id id) + (redirect-to "/")) + (redirect-to "/login?valuesofbetawillgiverisetodom=true")))))) + (GET "/" + (if (@session :id) + (.toString + (doto (.getInstanceOf templates "index") + (.setAttributes {"title" "Subscriptions", + "mainParagraph" "Hi there!"}))) + (redirect-to "/login"))) + (ANY "*" + (page-not-found))) + (defn trim-nil [thing] (and thing (.trim thing))) @@ -130,16 +139,8 @@ ;;;; Sample database content (comment - (with-dbt - (sql/update-or-insert-values :feed - ["id = ?" 0] - {:id 0 - :uri "http://matthias.benkard.de/journal/feed/"}) - (sql/update-or-insert-values :feed - ["id = ?" 1] - {:id 1 - :uri "http://uxul.wordpress.com/feed/"}))) - + (subscribe-to-feed "http://matthias.benkard.de/journal/feed/") + (subscribe-to-feed "http://uxul.wordpress.com/feed/")) ;;;; Database schema (comment diff --git a/login.st b/login.st new file mode 100644 index 0000000..41cd2fa --- /dev/null +++ b/login.st @@ -0,0 +1,18 @@ +<?xml version="1.0" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>$logintext$ — Gödel-Gentzen Clojure Syndication Services Super System</title> + </head> + + <body> + $logintext$ + <form method="POST"> + Username: <input name="name" type="text" /> <br /> + Password: <input name="password" type="password" /> <br /> + <input type="submit" value="Log In" /> + </form> + </body> +</html> |