Login, Logout and show update and delete below posts

This commit is contained in:
Jan-Lukas Else 2021-02-24 16:01:10 +01:00
parent 243d695bf4
commit b81f890120
7 changed files with 44 additions and 0 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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%;
}

View File

@ -169,6 +169,10 @@ footer {
display: none;
}
.in {
display: inline;
}
.fw {
width: 100%;
}

View File

@ -13,6 +13,7 @@
&bull; <a href="/notifications">{{ string .Blog.Lang "notifications" }}</a>
&bull; <a href="/webmention">{{ string .Blog.Lang "webmentions" }}</a>
&bull; <a href="{{ blogrelative .Blog "/comment" }}">{{ string .Blog.Lang "comments" }}</a>
&bull; <a href="/logout">{{ string .Blog.Lang "logout" }}</a>
</nav>
{{ end }}
</header>

View File

@ -27,6 +27,20 @@
</article>
{{ include "author" . }}
</main>
{{ if .LoggedIn }}
<div class="p">
<form class="in" method="post" action="{{ blogrelative .Blog "/editor" }}">
<input type="hidden" name="editoraction" value="loadupdate">
<input type="hidden" name="url" value="{{ .Canonical }}">
<input type="submit" value="{{ string .Blog.Lang "update" }}">
</form>
<form class="in" method="post" action="{{ blogrelative .Blog "/editor" }}">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="url" value="{{ .Canonical }}">
<input type="submit" value="{{ string .Blog.Lang "delete" }}">
</form>
</div>
{{ end }}
{{ if commentsenabled .Blog }}
{{ include "interactions" . }}
{{ end }}

View File

@ -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"