From 9d734af14b4a9870d554d4c15ee7e438ee81cc56 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 14 Feb 2025 17:06:22 +0000 Subject: [PATCH] htmx up the login page --- appview/pages/templates/user/login.html | 39 ++++++++++++++++++------- appview/state/state.go | 12 +++----- flake.nix | 5 +++- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/appview/pages/templates/user/login.html b/appview/pages/templates/user/login.html index 547ecfe3..283e0fe5 100644 --- a/appview/pages/templates/user/login.html +++ b/appview/pages/templates/user/login.html @@ -11,23 +11,40 @@ login - -
-

login

-
+ +
+

tangled.sh

+ +
- + +
+
+ type="password" + id="app_password" + name="app_password" + required + class="bg-gray-100 rounded p-1" + /> +
- + +

diff --git a/appview/state/state.go b/appview/state/state.go index 6d449a81..267201e9 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -77,29 +77,25 @@ func (s *State) Login(w http.ResponseWriter, r *http.Request) { } 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 } diff --git a/flake.nix b/flake.nix index 2ef89880..9c4756e1 100644 --- a/flake.nix +++ b/flake.nix @@ -67,7 +67,10 @@ 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 = { -- 2.51.2