diff options
Diffstat (limited to 'cljssss-g.clj')
-rw-r--r-- | cljssss-g.clj | 71 |
1 files changed, 36 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 |