feat: cookie authentication

use encrypted cookies to authenticate
basic auth feeds. most eReader browsers
don't support basic auth
This commit is contained in:
Evan Buss
2024-07-13 01:55:48 +00:00
parent f4408abeae
commit 4f3948943a
6 changed files with 196 additions and 11 deletions

View File

@@ -6,19 +6,36 @@ import (
"io"
"github.com/evan-buss/opds-proxy/opds"
sprig "github.com/go-task/slim-sprig/v3"
)
//go:embed *
var files embed.FS
var (
home = parse("home.html")
feed = parse("feed.html", "partials/search.html")
home = parse("home.html")
feed = parse("feed.html", "partials/search.html")
login = parse("login.html")
)
func parse(file ...string) *template.Template {
file = append(file, "layout.html")
return template.Must(template.New("layout.html").ParseFS(files, file...))
return template.Must(
template.New("layout.html").
Funcs(sprig.FuncMap()).
ParseFS(files, file...),
)
}
type LoginParams struct {
ReturnURL string
}
func Login(w io.Writer, p LoginParams, partial string) error {
if partial == "" {
partial = "layout.html"
}
return login.ExecuteTemplate(w, partial, p)
}
type FeedParams struct {

48
html/login.html Normal file
View File

@@ -0,0 +1,48 @@
{{ define "content" }}
<main>
<h1>{{index (urlParse .ReturnURL) "query" | trimPrefix "q=" }}</h1>
<p>Log in to access this feed</p>
<div id="content">
<form method="post">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<button type="submit">Log In</button>
</form>
</div>
</main>
<style>
main {
margin-top: 2rem;
text-align: center;
}
h1 {
font-size: 1.25rem;
}
form {
margin: 0 auto;
}
input {
appearance: none;
border: 1px solid rgb(0, 0, 0, 0.8);
display: block;
margin: 1rem auto;
padding: 0.8rem;
border-radius: 2px;
}
button {
font-style: normal;
padding: 0.8rem 1rem;
margin: 1rem auto;
display: block;
background-color: black;
color: white;
border: none;
border-radius: 2px;
}
</style>
{{ end }}

View File

@@ -101,3 +101,24 @@ a {
.nav-controls:last-child {
padding-right: 1rem;
}
*, *::before, *::after {
box-sizing: border-box;
}
* {
margin: 0;
}
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
img, picture, video, canvas, svg {
display: block;
max-width: 100%;
}
input, button, textarea, select {
font: inherit;
}
p, h1, h2, h3, h4, h5, h6 {
overflow-wrap: break-word;
}