Make login transparent for the user #25

This commit is contained in:
Aaron Fischer 2017-04-25 22:53:34 +02:00
parent 7ba26f7ed7
commit 771c50fb28
3 changed files with 23 additions and 23 deletions

View file

@ -6,7 +6,7 @@
<div class="col-lg-5 col-sm-12">
<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 %}
<div class="form-group">

View file

@ -1,24 +1,24 @@
(ns yenu.middleware
(:require [yenu.env :refer [defaults]]
[clojure.tools.logging :as log]
[yenu.layout :refer [*app-context* *identity* error-page]]
(:require [clojure.tools.logging :as log]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
[ring.middleware.webjars :refer [wrap-webjars]]
[ring.middleware.format :refer [wrap-restful-format]]
[yenu.config :refer [env]]
[ring.middleware.flash :refer [wrap-flash]]
[ring.middleware.cookies :refer [wrap-cookies]]
[immutant.web.middleware :refer [wrap-session]]
[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]]
[buddy.auth.accessrules :refer [success error]]
[clojure.tools.logging :as log]
[digest :as digest]
[buddy.auth :refer [authenticated?]])
[immutant.web.middleware :refer [wrap-session]]
[yenu.env :refer [defaults]]
[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]))
(defn wrap-context [handler]
@ -69,7 +69,7 @@
((if (:websocket? request) handler wrapped) request))))
(defn on-error [request response]
(redirect "/login"))
(redirect (format "/login?next=%s" (:uri request))))
(defn creator-access [request]
(let [identity (:identity request)]
@ -91,11 +91,10 @@
:handler authenticated?}])
(defn wrap-auth [handler]
(let [backend (session-backend)]
(-> handler
(wrap-access-rules {:rules rules :on-error on-error})
(wrap-authentication backend)
(wrap-authorization backend))))
(-> handler
(wrap-access-rules {:rules rules :on-error on-error})
(wrap-authentication session-backend)
(wrap-authorization session-backend)))
(defn wrap-base [handler]
(-> ((:middleware defaults) handler)

View file

@ -12,13 +12,14 @@
(defn login! [request]
(let [password (get-in request [:form-params "password"])
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
(let [updated-session (assoc session :identity user-identity)]
(-> (redirect "/page/1")
(-> (redirect next-url)
(assoc :flash {:message "Erfolgreich eingeloggt." :type "success"})
(assoc :session updated-session)))
(-> (redirect "/login")
(-> (redirect (format "/login?next=%s" next-url))
(assoc :flash {:message "Falsches Passwort." :type "danger"})))))
(defn logout! [request]