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 From ebdeda08f19dd1f18220727fe80906c0c18c0db4 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Fri, 20 Feb 2009 22:23:54 +0100 Subject: Add a URI parameter for invalid log-ins so that an error message can be displayed. --- cljssss-g.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cljssss-g.clj b/cljssss-g.clj index 3215bbb..ffb7ef2 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -33,7 +33,7 @@ (do (alter session assoc :id id) (redirect-to "/")) - (redirect-to "/login")))))) + (redirect-to "/login?valuesofbetawillgiverisetodom=true")))))) (ANY "*" (page-not-found))) -- cgit v1.2.3