convert info logs to debug to remove logging bloat
This commit is contained in:
parent
3e7b8a8b94
commit
f8d26675df
8 changed files with 72 additions and 72 deletions
|
@ -81,8 +81,6 @@
|
||||||
:infer-externs true
|
:infer-externs true
|
||||||
:closure-warnings
|
:closure-warnings
|
||||||
{:externs-validation :off :non-standard-jsdoc :off}}}}}
|
{:externs-validation :off :non-standard-jsdoc :off}}}}}
|
||||||
|
|
||||||
|
|
||||||
:aot :all
|
:aot :all
|
||||||
:uberjar-name "cat.jar"
|
:uberjar-name "cat.jar"
|
||||||
:source-paths ["env/prod/clj"]
|
:source-paths ["env/prod/clj"]
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
{% if message %}
|
{% if message %}
|
||||||
<h4 class="subtitle is-5 has-text-danger">{{message}}</h4>
|
<h4 class="subtitle is-5 has-text-danger">{{message}}</h4>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
(mount/defstate ^{:on-reload :noop} http-server
|
(mount/defstate ^{:on-reload :noop} http-server
|
||||||
:start
|
:start
|
||||||
(http/start
|
(http/start
|
||||||
(-> env
|
(-> env
|
||||||
(assoc :handler #'handler/app)
|
(assoc :handler #'handler/app)
|
||||||
(update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime)))))
|
(update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime)))))
|
||||||
(update :port #(or (-> env :options :port) %))))
|
(update :port #(or (-> env :options :port) %))))
|
||||||
:stop
|
:stop
|
||||||
(http/stop http-server))
|
(http/stop http-server))
|
||||||
|
|
||||||
|
@ -32,10 +32,9 @@
|
||||||
(when repl-server
|
(when repl-server
|
||||||
(nrepl/stop repl-server)))
|
(nrepl/stop repl-server)))
|
||||||
|
|
||||||
|
|
||||||
(defn stop-app []
|
(defn stop-app []
|
||||||
(doseq [component (:stopped (mount/stop))]
|
(doseq [component (:stopped (mount/stop))]
|
||||||
(log/info component "stopped"))
|
(log/debug component "stopped"))
|
||||||
(shutdown-agents))
|
(shutdown-agents))
|
||||||
|
|
||||||
(defn start-app [args]
|
(defn start-app [args]
|
||||||
|
@ -63,4 +62,3 @@
|
||||||
(System/exit 0))
|
(System/exit 0))
|
||||||
:else
|
:else
|
||||||
(start-app args)))
|
(start-app args)))
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
(:require [cat.middleware :as middleware]
|
(:require [cat.middleware :as middleware]
|
||||||
[cat.layout :refer [error-page]]
|
[cat.layout :refer [error-page]]
|
||||||
[cat.routes.home :refer [home-routes]]
|
[cat.routes.home :refer [home-routes]]
|
||||||
[cat.routes.oauth :refer [oauth-routes admin-routes]]
|
[cat.routes.oauth :refer [oauth-routes]]
|
||||||
|
[cat.routes.admin :refer [admin-routes]]
|
||||||
[compojure.core :refer [routes wrap-routes]]
|
[compojure.core :refer [routes wrap-routes]]
|
||||||
[ring.util.http-response :as response]
|
[ring.util.http-response :as response]
|
||||||
[compojure.route :as route]
|
[compojure.route :as route]
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
; To authorize, redirect the user to the sign in / grant page
|
; To authorize, redirect the user to the sign in / grant page
|
||||||
|
|
||||||
(defn- authorize-uri
|
(defn- authorize-uri
|
||||||
[client-params ;csrf-token
|
[client-params #_csrf-token]
|
||||||
]
|
|
||||||
(str
|
(str
|
||||||
(:authorize-uri client-params)
|
(:authorize-uri client-params)
|
||||||
"?"
|
"?"
|
||||||
|
@ -41,7 +40,7 @@
|
||||||
"let the user authorize access by redirecting to the signin / grant page
|
"let the user authorize access by redirecting to the signin / grant page
|
||||||
of the used oauth api"
|
of the used oauth api"
|
||||||
[]
|
[]
|
||||||
(log/info "Oauth params: " (oauth2-params))
|
; (log/info "Oauth params: " (oauth2-params))
|
||||||
(authorize-uri (oauth2-params)))
|
(authorize-uri (oauth2-params)))
|
||||||
|
|
||||||
(defn get-authentication-response
|
(defn get-authentication-response
|
||||||
|
@ -50,7 +49,7 @@
|
||||||
(if (or true (= csrf-token state))
|
(if (or true (= csrf-token state))
|
||||||
(try
|
(try
|
||||||
(do
|
(do
|
||||||
(log/info "Requesting access token with code " code)
|
(log/debug "Requesting access token with code " code)
|
||||||
(let [oauth2-params (oauth2-params)
|
(let [oauth2-params (oauth2-params)
|
||||||
access-token (httpclient/post (:access-token-uri oauth2-params)
|
access-token (httpclient/post (:access-token-uri oauth2-params)
|
||||||
{:form-params {:code code
|
{:form-params {:code code
|
||||||
|
|
41
src/clj/cat/routes/admin.clj
Normal file
41
src/clj/cat/routes/admin.clj
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
(ns cat.routes.admin
|
||||||
|
(:require [cat.db.core :refer [*db*] :as db]
|
||||||
|
[compojure.core :refer [defroutes GET POST]]
|
||||||
|
[struct.core :as st]
|
||||||
|
[clojure.tools.logging :as log]
|
||||||
|
[ring.util.http-response :as response]))
|
||||||
|
|
||||||
|
(def user-schema
|
||||||
|
[[:name st/required st/string]
|
||||||
|
[:gender st/string]])
|
||||||
|
|
||||||
|
(def relation-schema
|
||||||
|
[[:from_id st/required st/integer-str]
|
||||||
|
[:to_id st/required st/integer-str]])
|
||||||
|
|
||||||
|
(defroutes admin-routes
|
||||||
|
(GET "/admin/enable" req (-> (response/found "/")
|
||||||
|
(assoc :session (assoc-in (:session req) [:user :admin :enabled] true))))
|
||||||
|
(GET "/admin/disable" req (-> (response/found "/")
|
||||||
|
(assoc :session (assoc-in (:session req) [:user :admin :enabled] false))))
|
||||||
|
|
||||||
|
(POST "/relations" req
|
||||||
|
(let [data (:params req) [err result] (st/validate data relation-schema)]
|
||||||
|
(log/info "Post to " (:uri req))
|
||||||
|
(if (nil? err)
|
||||||
|
(do
|
||||||
|
(db/create-relation! result)
|
||||||
|
(response/found "/"))
|
||||||
|
(do
|
||||||
|
(response/bad-request "Incorrect input")))))
|
||||||
|
(POST "/users" req
|
||||||
|
(let [data (:params req)]
|
||||||
|
(log/info "Post to " (:uri req))
|
||||||
|
(println data)
|
||||||
|
(if (st/valid? data user-schema)
|
||||||
|
(do
|
||||||
|
(db/create-user! (assoc data :zeusid nil))
|
||||||
|
(response/found "/"))
|
||||||
|
(do
|
||||||
|
(response/bad-request "Incorrect input")))))
|
||||||
|
)
|
|
@ -9,14 +9,6 @@
|
||||||
[cat.layout :refer [error-page]]
|
[cat.layout :refer [error-page]]
|
||||||
[clojure.string :as s]))
|
[clojure.string :as s]))
|
||||||
|
|
||||||
(def user-schema
|
|
||||||
[[:name st/required st/string]
|
|
||||||
[:gender st/string]])
|
|
||||||
|
|
||||||
(def relation-schema
|
|
||||||
[[:from_id st/required st/integer-str]
|
|
||||||
[:to_id st/required st/integer-str]])
|
|
||||||
|
|
||||||
(def request_relation-schema
|
(def request_relation-schema
|
||||||
[[:to_id st/required st/integer-str]])
|
[[:to_id st/required st/integer-str]])
|
||||||
|
|
||||||
|
@ -53,7 +45,7 @@
|
||||||
rel-requests-out (seq (db/get-relation-requests-from-user {:from_id (:id user)}))
|
rel-requests-out (seq (db/get-relation-requests-from-user {:from_id (:id user)}))
|
||||||
rel-requests-in (seq (db/get-relation-requests-to-user {:to_id (:id user)}))
|
rel-requests-in (seq (db/get-relation-requests-to-user {:to_id (:id user)}))
|
||||||
non_requested_users (seq (filter (fn [other-user] (not (some (partial = (:id other-user)) (map :to_id rel-requests-out)))) other_users))]
|
non_requested_users (seq (filter (fn [other-user] (not (some (partial = (:id other-user)) (map :to_id rel-requests-out)))) other_users))]
|
||||||
(log/info (str "Session: " (:session req)))
|
(log/debug (str "Session: " (:session req)))
|
||||||
;(log/info (str "Relation requests: \n OUTGOING: " rel-requests-out "\n INCOMING: " rel-requests-in))
|
;(log/info (str "Relation requests: \n OUTGOING: " rel-requests-out "\n INCOMING: " rel-requests-in))
|
||||||
;(log/info (str "User relations: " user-relations))
|
;(log/info (str "User relations: " user-relations))
|
||||||
;(log/info (str "Other Users: " other_users))
|
;(log/info (str "Other Users: " other_users))
|
||||||
|
@ -118,7 +110,7 @@
|
||||||
(if (nil? from-id) (response/found (error-page
|
(if (nil? from-id) (response/found (error-page
|
||||||
{:status 400
|
{:status 400
|
||||||
:title "No user id found in session"})))
|
:title "No user id found in session"})))
|
||||||
(log/info "Post to " (:uri req) "\n with data " result)
|
(log/debug "Post to " (:uri req) "\n with data " result)
|
||||||
(if (nil? err)
|
(if (nil? err)
|
||||||
(do
|
(do
|
||||||
(log/debug "Create relation request")
|
(log/debug "Create relation request")
|
||||||
|
@ -129,28 +121,7 @@
|
||||||
(do
|
(do
|
||||||
(log/debug "Relation request failed")
|
(log/debug "Relation request failed")
|
||||||
(log/debug err)
|
(log/debug err)
|
||||||
(response/unprocessable-entity "Incorrect input")))))
|
(response/unprocessable-entity "Incorrect input"))))))
|
||||||
|
|
||||||
; TODO make bottom 2 admin protected
|
|
||||||
(POST "/relations" req
|
|
||||||
(let [data (:params req) [err result] (st/validate data relation-schema)]
|
|
||||||
(log/info "Post to " (:uri req))
|
|
||||||
(if (nil? err)
|
|
||||||
(do
|
|
||||||
(db/create-relation! result)
|
|
||||||
(response/found "/"))
|
|
||||||
(do
|
|
||||||
(response/bad-request "Incorrect input")))))
|
|
||||||
(POST "/users" req
|
|
||||||
(let [data (:params req)]
|
|
||||||
(log/info "Post to " (:uri req))
|
|
||||||
(println data)
|
|
||||||
(if (st/valid? data user-schema)
|
|
||||||
(do
|
|
||||||
(db/create-user! (assoc data :zeusid nil))
|
|
||||||
(response/found "/"))
|
|
||||||
(do
|
|
||||||
(response/bad-request "Incorrect input"))))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
(def admins [{:name "flynn" :zeusid 117}])
|
(def admins [{:name "flynn" :zeusid 117}])
|
||||||
|
|
||||||
(defn set-user! [user session redirect-url]
|
(defn set-user! [user session redirect-url]
|
||||||
(log/info "Set user in session: " user)
|
(log/debug "Set user in session: " user)
|
||||||
(let [new-session (-> session
|
(let [new-session (-> session
|
||||||
(assoc :user user)
|
(assoc :user user)
|
||||||
(cond-> (some (partial = (select-keys user [:zeusid :name])) admins)
|
(cond-> (some (partial = (select-keys user [:zeusid :name])) admins)
|
||||||
(->
|
(->
|
||||||
(assoc-in [:user :admin] {:enabled false})
|
(assoc-in [:user :admin] {:enabled false})
|
||||||
(assoc :identity "foo"))))]
|
(assoc :identity "foo"))))]
|
||||||
(-> (found redirect-url)
|
(-> (found redirect-url)
|
||||||
(assoc :session new-session))))
|
(assoc :session new-session))))
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
"Initiates the Twitter OAuth"
|
"Initiates the Twitter OAuth"
|
||||||
[request]
|
[request]
|
||||||
(let [reee (mo/authorize-api-uri)]
|
(let [reee (mo/authorize-api-uri)]
|
||||||
(log/info "authorize uri: " reee)
|
(log/debug "authorize uri: " reee)
|
||||||
(-> reee
|
(-> reee
|
||||||
found)))
|
found)))
|
||||||
|
|
||||||
|
@ -47,12 +47,12 @@
|
||||||
(assoc :flash {:denied true}))
|
(assoc :flash {:denied true}))
|
||||||
; fetch the request token and do anything else you wanna do if not denied.
|
; fetch the request token and do anything else you wanna do if not denied.
|
||||||
(let [{:keys [access_token refresh_token]} (mo/get-authentication-response nil req_token)]
|
(let [{:keys [access_token refresh_token]} (mo/get-authentication-response nil req_token)]
|
||||||
(log/info "Successfully fetched access-id: " access_token)
|
(log/debug "Successfully fetched access-id: " access_token)
|
||||||
(log/info "Fetching user info")
|
(log/debug "Fetching user info")
|
||||||
(let [fetched-user (mo/get-user-info access_token)]
|
(let [fetched-user (mo/get-user-info access_token)]
|
||||||
(log/info "Fetched user info: " fetched-user)
|
(log/debug "Fetched user info: " fetched-user)
|
||||||
(let [local-user (db/get-zeus-user {:zeusid (:id fetched-user)})]
|
(let [local-user (db/get-zeus-user {:zeusid (:id fetched-user)})]
|
||||||
(log/info "Zeus user from db: " local-user)
|
(log/debug "Zeus user from db: " local-user)
|
||||||
(if local-user
|
(if local-user
|
||||||
(set-user! local-user session "/")
|
(set-user! local-user session "/")
|
||||||
(try
|
(try
|
||||||
|
@ -60,16 +60,15 @@
|
||||||
:gender nil
|
:gender nil
|
||||||
:zeusid (:id fetched-user)}
|
:zeusid (:id fetched-user)}
|
||||||
generated-key (-> user-template
|
generated-key (-> user-template
|
||||||
(db/create-user!,,,))]
|
(db/create-user!))]
|
||||||
(log/info "Created user: " generated-key)
|
(log/debug "Created user: " generated-key)
|
||||||
(set-user! (assoc user-template :id (:generated_key generated-key)) session "/"))
|
(set-user! (assoc user-template :id (:generated_key generated-key)) session "/"))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(do
|
(do
|
||||||
(log/warn "fetched user" fetched-user "already exists, but was not found")
|
(log/warn "fetched user" fetched-user "already exists, but was not found")
|
||||||
(log/warn (:cause (Throwable->map e)))
|
(log/warn (:cause (Throwable->map e)))
|
||||||
(-> (found "/")
|
(-> (found "/")
|
||||||
(assoc :flash {:error "An error occurred, please try again."})))
|
(assoc :flash {:error "An error occurred, please try again."})))))))))))
|
||||||
))))))))
|
|
||||||
|
|
||||||
;(catch [:status 401] _
|
;(catch [:status 401] _
|
||||||
; (error-page {:status 401
|
; (error-page {:status 401
|
||||||
|
@ -78,12 +77,6 @@
|
||||||
|
|
||||||
|
|
||||||
(defroutes oauth-routes
|
(defroutes oauth-routes
|
||||||
(GET "/oauth/oauth-init" req (oauth-init req))
|
(GET "/oauth/oauth-init" req (oauth-init req))
|
||||||
(GET "/oauth/oauth-callback" [& req_token :as req] (oauth-callback req_token req))
|
(GET "/oauth/oauth-callback" [& req_token :as req] (oauth-callback req_token req))
|
||||||
(GET "/logout" req (clear-session! "/")))
|
(GET "/logout" req (clear-session! "/")))
|
||||||
|
|
||||||
(defroutes admin-routes
|
|
||||||
(GET "/admin/enable" req (-> (found "/")
|
|
||||||
(assoc :session (assoc-in (:session req) [:user :admin :enabled] true))))
|
|
||||||
(GET "/admin/disable" req (-> (found "/")
|
|
||||||
(assoc :session (assoc-in (:session req) [:user :admin :enabled] false)))))
|
|
||||||
|
|
Loading…
Reference in a new issue