Make login transparent for the user #25
This commit is contained in:
parent
7ba26f7ed7
commit
771c50fb28
3 changed files with 23 additions and 23 deletions
|
@ -6,7 +6,7 @@
|
||||||
<div class="col-lg-5 col-sm-12">
|
<div class="col-lg-5 col-sm-12">
|
||||||
<p>Um die Seite anzusehen oder die Aktion auszuführen wird ein Passwort benötigt.</p>
|
<p>Um die Seite anzusehen oder die Aktion auszuführen wird ein Passwort benötigt.</p>
|
||||||
|
|
||||||
<form action="/login" method="POST" class="form-horizontal">
|
<form method="POST" class="form-horizontal">
|
||||||
{% csrf-field %}
|
{% csrf-field %}
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
(ns yenu.middleware
|
(ns yenu.middleware
|
||||||
(:require [yenu.env :refer [defaults]]
|
(:require [clojure.tools.logging :as log]
|
||||||
[clojure.tools.logging :as log]
|
|
||||||
[yenu.layout :refer [*app-context* *identity* error-page]]
|
|
||||||
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
|
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
|
||||||
[ring.middleware.webjars :refer [wrap-webjars]]
|
[ring.middleware.webjars :refer [wrap-webjars]]
|
||||||
[ring.middleware.format :refer [wrap-restful-format]]
|
[ring.middleware.format :refer [wrap-restful-format]]
|
||||||
[yenu.config :refer [env]]
|
|
||||||
[ring.middleware.flash :refer [wrap-flash]]
|
[ring.middleware.flash :refer [wrap-flash]]
|
||||||
[ring.middleware.cookies :refer [wrap-cookies]]
|
[ring.middleware.cookies :refer [wrap-cookies]]
|
||||||
[immutant.web.middleware :refer [wrap-session]]
|
|
||||||
[ring.middleware.defaults :refer [site-defaults wrap-defaults]]
|
[ring.middleware.defaults :refer [site-defaults wrap-defaults]]
|
||||||
[buddy.auth.middleware :refer [wrap-authentication wrap-authorization]]
|
|
||||||
[buddy.auth.accessrules :refer [wrap-access-rules]]
|
|
||||||
[buddy.auth.backends.session :refer [session-backend]]
|
|
||||||
[buddy.auth.accessrules :refer [restrict]]
|
|
||||||
[ring.util.response :refer [redirect]]
|
[ring.util.response :refer [redirect]]
|
||||||
[buddy.auth.accessrules :refer [success error]]
|
[immutant.web.middleware :refer [wrap-session]]
|
||||||
[clojure.tools.logging :as log]
|
|
||||||
[digest :as digest]
|
[yenu.env :refer [defaults]]
|
||||||
[buddy.auth :refer [authenticated?]])
|
[yenu.config :refer [env]]
|
||||||
|
[yenu.layout :refer [*app-context* *identity* error-page]]
|
||||||
|
|
||||||
|
[buddy.auth :refer [authenticated?]]
|
||||||
|
[buddy.auth.middleware :refer [wrap-authentication wrap-authorization]]
|
||||||
|
[buddy.auth.backends.session :refer [session-backend]]
|
||||||
|
[buddy.auth.accessrules :refer [wrap-access-rules success error restrict]]
|
||||||
|
|
||||||
|
[digest :as digest])
|
||||||
(:import [javax.servlet ServletContext]))
|
(:import [javax.servlet ServletContext]))
|
||||||
|
|
||||||
(defn wrap-context [handler]
|
(defn wrap-context [handler]
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
((if (:websocket? request) handler wrapped) request))))
|
((if (:websocket? request) handler wrapped) request))))
|
||||||
|
|
||||||
(defn on-error [request response]
|
(defn on-error [request response]
|
||||||
(redirect "/login"))
|
(redirect (format "/login?next=%s" (:uri request))))
|
||||||
|
|
||||||
(defn creator-access [request]
|
(defn creator-access [request]
|
||||||
(let [identity (:identity request)]
|
(let [identity (:identity request)]
|
||||||
|
@ -91,11 +91,10 @@
|
||||||
:handler authenticated?}])
|
:handler authenticated?}])
|
||||||
|
|
||||||
(defn wrap-auth [handler]
|
(defn wrap-auth [handler]
|
||||||
(let [backend (session-backend)]
|
(-> handler
|
||||||
(-> handler
|
(wrap-access-rules {:rules rules :on-error on-error})
|
||||||
(wrap-access-rules {:rules rules :on-error on-error})
|
(wrap-authentication session-backend)
|
||||||
(wrap-authentication backend)
|
(wrap-authorization session-backend)))
|
||||||
(wrap-authorization backend))))
|
|
||||||
|
|
||||||
(defn wrap-base [handler]
|
(defn wrap-base [handler]
|
||||||
(-> ((:middleware defaults) handler)
|
(-> ((:middleware defaults) handler)
|
||||||
|
|
|
@ -12,13 +12,14 @@
|
||||||
(defn login! [request]
|
(defn login! [request]
|
||||||
(let [password (get-in request [:form-params "password"])
|
(let [password (get-in request [:form-params "password"])
|
||||||
session (:session request)
|
session (:session request)
|
||||||
user-identity (valid-identity password)]
|
user-identity (valid-identity password)
|
||||||
|
next-url (get-in request [:params :next] "/page/1")]
|
||||||
(if user-identity
|
(if user-identity
|
||||||
(let [updated-session (assoc session :identity user-identity)]
|
(let [updated-session (assoc session :identity user-identity)]
|
||||||
(-> (redirect "/page/1")
|
(-> (redirect next-url)
|
||||||
(assoc :flash {:message "Erfolgreich eingeloggt." :type "success"})
|
(assoc :flash {:message "Erfolgreich eingeloggt." :type "success"})
|
||||||
(assoc :session updated-session)))
|
(assoc :session updated-session)))
|
||||||
(-> (redirect "/login")
|
(-> (redirect (format "/login?next=%s" next-url))
|
||||||
(assoc :flash {:message "Falsches Passwort." :type "danger"})))))
|
(assoc :flash {:message "Falsches Passwort." :type "danger"})))))
|
||||||
|
|
||||||
(defn logout! [request]
|
(defn logout! [request]
|
||||||
|
|
Loading…
Reference in a new issue