From 6ec04ffff7bd50a80ca54b79217a3d0fdd61f34c Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Fri, 20 Feb 2009 22:19:54 +0100 Subject: Add beginnings of log-in handling. --- cljssss-g.clj | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cljssss-g.clj b/cljssss-g.clj index e79afa6..3215bbb 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -14,10 +14,26 @@ (defservlet cljssss-g (GET "/" - (.toString - (doto (.getInstanceOf templates "index") - (.setAttributes {"title" "Subscriptions", - "mainParagraph" "Hi there!"})))) + (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")))))) (ANY "*" (page-not-found))) -- cgit v1.2.3