From b81f890120eaf61d459ee5e28bb8cb02d90e1ae6 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Wed, 24 Feb 2021 16:01:10 +0100 Subject: [PATCH] Login, Logout and show update and delete below posts --- authentication.go | 16 ++++++++++++++++ http.go | 4 ++++ templates/assets/css/styles.css | 4 ++++ templates/assets/css/styles.scss | 4 ++++ templates/header.gohtml | 1 + templates/post.gohtml | 14 ++++++++++++++ templates/strings/default.yaml | 1 + 7 files changed, 44 insertions(+) diff --git a/authentication.go b/authentication.go index 315b130..6f052f3 100644 --- a/authentication.go +++ b/authentication.go @@ -157,3 +157,19 @@ func createTokenCookie(username string) (*http.Cookie, error) { SameSite: http.SameSiteLaxMode, }, nil } + +// Need to set auth middleware! +func serveLogin(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/", http.StatusFound) +} + +func serveLogout(w http.ResponseWriter, r *http.Request) { + http.SetCookie(w, &http.Cookie{ + Name: "token", + MaxAge: -1, + Secure: httpsConfigured(), + HttpOnly: true, + SameSite: http.SameSiteLaxMode, + }) + http.Redirect(w, r, "/", http.StatusFound) +} diff --git a/http.go b/http.go index 6ff0b0e..2a721a8 100644 --- a/http.go +++ b/http.go @@ -100,6 +100,10 @@ func buildHandler() (http.Handler, error) { r.Use(checkIsCaptcha) r.Use(checkLoggedIn) + // Logout + r.With(authMiddleware).Get("/login", serveLogin) + r.With(authMiddleware).Get("/logout", serveLogout) + // Micropub r.Route(micropubPath, func(mpRouter chi.Router) { mpRouter.Use(checkIndieAuth) diff --git a/templates/assets/css/styles.css b/templates/assets/css/styles.css index e4a5b1a..337d70c 100644 --- a/templates/assets/css/styles.css +++ b/templates/assets/css/styles.css @@ -142,6 +142,10 @@ footer * { display: none; } +.in { + display: inline; +} + .fw, .fw-form, .fw-form input:not([type]), .fw-form input[type=text], .fw-form input[type=email], .fw-form input[type=url], .fw-form input[type=password], .fw-form textarea { width: 100%; } diff --git a/templates/assets/css/styles.scss b/templates/assets/css/styles.scss index 78fb61b..6ffd1a5 100644 --- a/templates/assets/css/styles.scss +++ b/templates/assets/css/styles.scss @@ -169,6 +169,10 @@ footer { display: none; } +.in { + display: inline; +} + .fw { width: 100%; } diff --git a/templates/header.gohtml b/templates/header.gohtml index 55f23ef..dcfd436 100644 --- a/templates/header.gohtml +++ b/templates/header.gohtml @@ -13,6 +13,7 @@ • {{ string .Blog.Lang "notifications" }}{{ string .Blog.Lang "webmentions" }}{{ string .Blog.Lang "comments" }} + • {{ string .Blog.Lang "logout" }} {{ end }} diff --git a/templates/post.gohtml b/templates/post.gohtml index 58cbf02..cdfe6ea 100644 --- a/templates/post.gohtml +++ b/templates/post.gohtml @@ -27,6 +27,20 @@ {{ include "author" . }} + {{ if .LoggedIn }} +
+
+ + + +
+
+ + + +
+
+ {{ end }} {{ if commentsenabled .Blog }} {{ include "interactions" . }} {{ end }} diff --git a/templates/strings/default.yaml b/templates/strings/default.yaml index c2f7a99..e6d8af1 100644 --- a/templates/strings/default.yaml +++ b/templates/strings/default.yaml @@ -17,6 +17,7 @@ interactions: "Interactions & Comments" interactionslabel: "Have you published a response to this? Paste the URL here." likeof: "Like of" login: "Login" +logout: "Logout" nameopt: "Name (optional)" next: "Next" notifications: "Notifications"