From 564cfdd2e0f781362fe1bad3cf8c9015e01c48d7 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 7 Aug 2025 16:44:12 +0100 Subject: [PATCH] appview/pages: rework signup pages - new /signup page to enter email ID - login page has a link to go signup - signup page has a link to go back to login Signed-off-by: oppiliappan --- appview/pages/pages.go | 8 +- appview/pages/templates/layouts/topbar.html | 4 + .../pages/templates/user/completeSignup.html | 10 +- appview/pages/templates/user/login.html | 90 ++------------- appview/pages/templates/user/signup.html | 53 +++++++++ appview/signup/signup.go | 105 ++++++++++-------- 6 files changed, 134 insertions(+), 136 deletions(-) create mode 100644 appview/pages/templates/user/signup.html diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 6785bff2..2608c0f8 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -262,10 +262,12 @@ func (p *Pages) Login(w io.Writer, params LoginParams) error { return p.executePlain("user/login", w, params) } -type SignupParams struct{} +func (p *Pages) Signup(w io.Writer) error { + return p.executePlain("user/signup", w, nil) +} -func (p *Pages) CompleteSignup(w io.Writer, params SignupParams) error { - return p.executePlain("user/completeSignup", w, params) +func (p *Pages) CompleteSignup(w io.Writer) error { + return p.executePlain("user/completeSignup", w, nil) } type TermsOfServiceParams struct { diff --git a/appview/pages/templates/layouts/topbar.html b/appview/pages/templates/layouts/topbar.html index 36878eb7..7ffd9110 100644 --- a/appview/pages/templates/layouts/topbar.html +++ b/appview/pages/templates/layouts/topbar.html @@ -15,6 +15,10 @@ {{ block "dropDown" . }} {{ end }} {{ else }} login + or + + join now {{ i "arrow-right" "size-4" }} + {{ end }} diff --git a/appview/pages/templates/user/completeSignup.html b/appview/pages/templates/user/completeSignup.html index c24a8e65..6582b5e7 100644 --- a/appview/pages/templates/user/completeSignup.html +++ b/appview/pages/templates/user/completeSignup.html @@ -38,7 +38,7 @@ tightly-knit social coding.
-
- +
+
-
+
-
-

- Alternatively, you may create an account on Tangled below. You will - get a user.tngl.sh handle. +

+ Don't have an account? Create an account on Tangled now!

-
- - - create an account - -
{{ i "arrow-right" "w-4 h-4" }}
- -
-
-
- - -
- - You will receive an email with a code. Enter that, along with your - desired username and password in the next page to complete your registration. - - -
-
-

- Join our Discord or - IRC channel: - #tangled on Libera Chat. -

diff --git a/appview/pages/templates/user/signup.html b/appview/pages/templates/user/signup.html new file mode 100644 index 00000000..44135f67 --- /dev/null +++ b/appview/pages/templates/user/signup.html @@ -0,0 +1,53 @@ +{{ define "user/signup" }} + + + + + + + + + + + sign up · tangled + + +
+

tangled

+

tightly-knit social coding.

+
+
+ + +
+ + You will receive an email with an invite code. Enter your + invite code, desired username, and password in the next + page to complete your registration. + + +
+

+ Already have an account? Login to Tangled. +

+ +

+
+ + +{{ end }} + diff --git a/appview/signup/signup.go b/appview/signup/signup.go index f8bbe07a..fcadd7da 100644 --- a/appview/signup/signup.go +++ b/appview/signup/signup.go @@ -104,6 +104,7 @@ func (s *Signup) isNicknameAllowed(nickname string) bool { func (s *Signup) Router() http.Handler { r := chi.NewRouter() + r.Get("/", s.signup) r.Post("/", s.signup) r.Get("/complete", s.complete) r.Post("/complete", s.complete) @@ -112,68 +113,74 @@ func (s *Signup) Router() http.Handler { } func (s *Signup) signup(w http.ResponseWriter, r *http.Request) { - if s.cf == nil { - http.Error(w, "signup is disabled", http.StatusFailedDependency) - } - emailId := r.FormValue("email") + switch r.Method { + case http.MethodGet: + s.pages.Signup(w) + case http.MethodPost: + if s.cf == nil { + http.Error(w, "signup is disabled", http.StatusFailedDependency) + } + emailId := r.FormValue("email") - if !email.IsValidEmail(emailId) { - s.pages.Notice(w, "login-msg", "Invalid email address.") - return - } + noticeId := "signup-msg" + if !email.IsValidEmail(emailId) { + s.pages.Notice(w, noticeId, "Invalid email address.") + return + } - exists, err := db.CheckEmailExistsAtAll(s.db, emailId) - if err != nil { - s.l.Error("failed to check email existence", "error", err) - s.pages.Notice(w, "login-msg", "Failed to complete signup. Try again later.") - return - } - if exists { - s.pages.Notice(w, "login-msg", "Email already exists.") - return - } + exists, err := db.CheckEmailExistsAtAll(s.db, emailId) + if err != nil { + s.l.Error("failed to check email existence", "error", err) + s.pages.Notice(w, noticeId, "Failed to complete signup. Try again later.") + return + } + if exists { + s.pages.Notice(w, noticeId, "Email already exists.") + return + } - code, err := s.inviteCodeRequest() - if err != nil { - s.l.Error("failed to create invite code", "error", err) - s.pages.Notice(w, "login-msg", "Failed to create invite code.") - return - } + code, err := s.inviteCodeRequest() + if err != nil { + s.l.Error("failed to create invite code", "error", err) + s.pages.Notice(w, noticeId, "Failed to create invite code.") + return + } - em := email.Email{ - APIKey: s.config.Resend.ApiKey, - From: s.config.Resend.SentFrom, - To: emailId, - Subject: "Verify your Tangled account", - Text: `Copy and paste this code below to verify your account on Tangled. + em := email.Email{ + APIKey: s.config.Resend.ApiKey, + From: s.config.Resend.SentFrom, + To: emailId, + Subject: "Verify your Tangled account", + Text: `Copy and paste this code below to verify your account on Tangled. ` + code, - Html: `

Copy and paste this code below to verify your account on Tangled.

+ Html: `

Copy and paste this code below to verify your account on Tangled.

` + code + `

`, - } + } - err = email.SendEmail(em) - if err != nil { - s.l.Error("failed to send email", "error", err) - s.pages.Notice(w, "login-msg", "Failed to send email.") - return - } - err = db.AddInflightSignup(s.db, db.InflightSignup{ - Email: emailId, - InviteCode: code, - }) - if err != nil { - s.l.Error("failed to add inflight signup", "error", err) - s.pages.Notice(w, "login-msg", "Failed to complete sign up. Try again later.") - return - } + err = email.SendEmail(em) + if err != nil { + s.l.Error("failed to send email", "error", err) + s.pages.Notice(w, noticeId, "Failed to send email.") + return + } + err = db.AddInflightSignup(s.db, db.InflightSignup{ + Email: emailId, + InviteCode: code, + }) + if err != nil { + s.l.Error("failed to add inflight signup", "error", err) + s.pages.Notice(w, noticeId, "Failed to complete sign up. Try again later.") + return + } - s.pages.HxRedirect(w, "/signup/complete") + s.pages.HxRedirect(w, "/signup/complete") + } } func (s *Signup) complete(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: - s.pages.CompleteSignup(w, pages.SignupParams{}) + s.pages.CompleteSignup(w) case http.MethodPost: username := r.FormValue("username") password := r.FormValue("password") -- 2.51.2