aboutsummaryrefslogtreecommitdiff
path: root/cljssss-g.clj
diff options
context:
space:
mode:
Diffstat (limited to 'cljssss-g.clj')
-rw-r--r--cljssss-g.clj59
1 files changed, 30 insertions, 29 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj
index 0588a59..f57275f 100644
--- a/cljssss-g.clj
+++ b/cljssss-g.clj
@@ -12,6 +12,19 @@
(def templates (new StringTemplateGroup ""))
+(def db-connection-data {:classname "org.sqlite.JDBC"
+ :subprotocol "sqlite"
+ :subname "cljssss-g.sqlite3"
+ :create true})
+
+(defmacro with-db [& body]
+ `(sql/with-connection db-connection-data
+ ~@body))
+
+(defmacro with-dbt [& body]
+ `(with-db
+ (sql/transaction
+ ~@body)))
(defn login-view []
(.toString (.getInstanceOf templates "login")))
@@ -19,7 +32,7 @@
(defservlet cljssss-g
(GET "/login"
- (if (= (params :wrong) "true")
+ (if (= (params :valuesofbetawillgiverisetodom) "true")
(.toString (doto
(.getInstanceOf templates "login")
(.setAttributes {"logintext" "Login failed"})))
@@ -28,37 +41,25 @@
(.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?wrong=true"))))))
- (GET "/blah/"
- (.toString
- (doto (.getInstanceOf templates "index")
- (.setAttributes {"title" "Subscriptions",
- "mainParagraph" "Hi there!"}))))
+ (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)))
-(def db-connection-data {:classname "org.sqlite.JDBC"
- :subprotocol "sqlite"
- :subname "cljssss-g.sqlite3"
- :create true})
-
-(defmacro with-db [& body]
- `(sql/with-connection db-connection-data
- ~@body))
-
-(defmacro with-dbt [& body]
- `(with-db
- (sql/transaction
- ~@body)))
-
(defn trim-nil [thing]
(and thing (.trim thing)))