+28
-11
appview/pages/templates/user/login.html
+28
-11
appview/pages/templates/user/login.html
···
11
11
<link rel="stylesheet" href="/static/tw.css" type="text/css" />
12
12
<title>login</title>
13
13
</head>
14
-
<body>
15
-
<main class="content">
16
-
<h1>login</h1>
17
-
<form method="POST" action="/login">
14
+
<body class="flex items-center justify-center min-h-screen">
15
+
<main class="max-w-64">
16
+
<h1 class="text-center text-2xl font-semibold">tangled.sh</h1>
17
+
<form class="w-full" hx-post="/login" hx-swap="none" hx-disabled-elt="this">
18
+
<div class="flex flex-col">
18
19
<label for="handle">handle</label>
19
-
<input type="text" id="handle" name="handle" required />
20
+
<input
21
+
type="text"
22
+
id="handle"
23
+
name="handle"
24
+
required
25
+
class="bg-gray-100 rounded p-1"
26
+
/>
27
+
</div>
20
28
29
+
<div class="flex flex-col mt-2">
21
30
<label for="app_password">app password</label>
22
31
<input
23
-
type="password"
24
-
id="app_password"
25
-
name="app_password"
26
-
required
27
-
/>
32
+
type="password"
33
+
id="app_password"
34
+
name="app_password"
35
+
required
36
+
class="bg-gray-100 rounded p-1"
37
+
/>
38
+
</div>
28
39
29
-
<button class="btn my-2" type="submit">login</button>
40
+
<button
41
+
class="btn w-full my-2 mt-6"
42
+
type="submit"
43
+
id="login-button">
44
+
<span>login</span>
45
+
</button>
30
46
</form>
47
+
<p id="login-msg" class="error w-full"></p>
31
48
</main>
32
49
</body>
33
50
</html>
+4
-8
appview/state/state.go
+4
-8
appview/state/state.go
···
77
77
}
78
78
return
79
79
case http.MethodPost:
80
-
handle := r.FormValue("handle")
80
+
handle := strings.TrimPrefix(r.FormValue("handle"), "@")
81
81
appPassword := r.FormValue("app_password")
82
82
83
-
fmt.Println("handle", handle)
84
-
fmt.Println("app_password", appPassword)
85
-
86
83
resolved, err := s.resolver.ResolveIdent(ctx, handle)
87
84
if err != nil {
88
-
log.Printf("resolving identity: %s", err)
89
-
http.Redirect(w, r, "/login", http.StatusSeeOther)
85
+
s.pages.Notice(w, "login-msg", fmt.Sprintf("\"%s\" is an invalid handle.", handle))
90
86
return
91
87
}
92
88
93
89
atSession, err := s.auth.CreateInitialSession(ctx, resolved, appPassword)
94
90
if err != nil {
95
-
log.Printf("creating initial session: %s", err)
91
+
s.pages.Notice(w, "login-msg", "Invalid handle or password.")
96
92
return
97
93
}
98
94
sessionish := auth.CreateSessionWrapper{ServerCreateSession_Output: atSession}
99
95
100
96
err = s.auth.StoreSession(r, w, &sessionish, resolved.PDSEndpoint())
101
97
if err != nil {
102
-
log.Printf("storing session: %s", err)
98
+
s.pages.Notice(w, "login-msg", "Failed to login, try again later.")
103
99
return
104
100
}
105
101
+4
-1
flake.nix
+4
-1
flake.nix
···
67
67
air-watcher = name:
68
68
pkgs.writeShellScriptBin "run"
69
69
''
70
-
${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"
70
+
${pkgs.air}/bin/air -c /dev/null \
71
+
-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" \
72
+
-build.bin "./out/${name}.out" \
73
+
-build.include_ext "go,html,css"
71
74
'';
72
75
in {
73
76
watch-appview = {