forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

htmx up the login page

Changed files
+36 -20
appview
pages
templates
user
state
+28 -11
appview/pages/templates/user/login.html
···
<link rel="stylesheet" href="/static/tw.css" type="text/css" />
<title>login</title>
</head>
-
<body>
-
<main class="content">
-
<h1>login</h1>
-
<form method="POST" action="/login">
+
<body class="flex items-center justify-center min-h-screen">
+
<main class="max-w-64">
+
<h1 class="text-center text-2xl font-semibold">tangled.sh</h1>
+
<form class="w-full" hx-post="/login" hx-swap="none" hx-disabled-elt="this">
+
<div class="flex flex-col">
<label for="handle">handle</label>
-
<input type="text" id="handle" name="handle" required />
+
<input
+
type="text"
+
id="handle"
+
name="handle"
+
required
+
class="bg-gray-100 rounded p-1"
+
/>
+
</div>
+
<div class="flex flex-col mt-2">
<label for="app_password">app password</label>
<input
-
type="password"
-
id="app_password"
-
name="app_password"
-
required
-
/>
+
type="password"
+
id="app_password"
+
name="app_password"
+
required
+
class="bg-gray-100 rounded p-1"
+
/>
+
</div>
-
<button class="btn my-2" type="submit">login</button>
+
<button
+
class="btn w-full my-2 mt-6"
+
type="submit"
+
id="login-button">
+
<span>login</span>
+
</button>
</form>
+
<p id="login-msg" class="error w-full"></p>
</main>
</body>
</html>
+4 -8
appview/state/state.go
···
}
return
case http.MethodPost:
-
handle := r.FormValue("handle")
+
handle := strings.TrimPrefix(r.FormValue("handle"), "@")
appPassword := r.FormValue("app_password")
-
fmt.Println("handle", handle)
-
fmt.Println("app_password", appPassword)
-
resolved, err := s.resolver.ResolveIdent(ctx, handle)
if err != nil {
-
log.Printf("resolving identity: %s", err)
-
http.Redirect(w, r, "/login", http.StatusSeeOther)
+
s.pages.Notice(w, "login-msg", fmt.Sprintf("\"%s\" is an invalid handle.", handle))
return
}
atSession, err := s.auth.CreateInitialSession(ctx, resolved, appPassword)
if err != nil {
-
log.Printf("creating initial session: %s", err)
+
s.pages.Notice(w, "login-msg", "Invalid handle or password.")
return
}
sessionish := auth.CreateSessionWrapper{ServerCreateSession_Output: atSession}
err = s.auth.StoreSession(r, w, &sessionish, resolved.PDSEndpoint())
if err != nil {
-
log.Printf("storing session: %s", err)
+
s.pages.Notice(w, "login-msg", "Failed to login, try again later.")
return
}
+4 -1
flake.nix
···
air-watcher = name:
pkgs.writeShellScriptBin "run"
''
-
${pkgs.air}/bin/air -c /dev/null -build.cmd "cp ${htmx-src} appview/pages/static/htmx.min.js && ${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o ./appview/pages/static/tw.css && ${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" -build.bin "./out/${name}.out"
+
${pkgs.air}/bin/air -c /dev/null \
+
-build.cmd "cp -f ${htmx-src} appview/pages/static/htmx.min.js && ${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o ./appview/pages/static/tw.css && ${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \
+
-build.bin "./out/${name}.out" \
+
-build.include_ext "go,html,css"
'';
in {
watch-appview = {