summaryrefslogtreecommitdiff
path: root/internal/web/confirmemail.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-04-11 11:45:53 +0200
committerLibravatar GitHub <noreply@github.com>2024-04-11 11:45:53 +0200
commit9fb8a78f91adffd5f4d28df1270e407c25a7a16e (patch)
treed68200744e28d07e75a52bb0c9f6593c86a38a91 /internal/web/confirmemail.go
parent[performance] massively improved ActivityPub delivery worker efficiency (#2812) (diff)
downloadgotosocial-9fb8a78f91adffd5f4d28df1270e407c25a7a16e.tar.xz
[feature] New user sign-up via web page (#2796)
* [feature] User sign-up form and admin notifs * add chosen + filtered languages to migration * remove stray comment * chosen languages schmosen schmanguages * proper error on local account missing
Diffstat (limited to 'internal/web/confirmemail.go')
-rw-r--r--internal/web/confirmemail.go68
1 files changed, 67 insertions, 1 deletions
diff --git a/internal/web/confirmemail.go b/internal/web/confirmemail.go
index f15252bf7..e512761f4 100644
--- a/internal/web/confirmemail.go
+++ b/internal/web/confirmemail.go
@@ -56,18 +56,84 @@ func (m *Module) confirmEmailGETHandler(c *gin.Context) {
return
}
+ // Get user but don't confirm yet.
+ user, errWithCode := m.processor.User().EmailGetUserForConfirmToken(c.Request.Context(), token)
+ if errWithCode != nil {
+ apiutil.WebErrorHandler(c, errWithCode, instanceGet)
+ return
+ }
+
+ // They may have already confirmed before
+ // and are visiting the link again for
+ // whatever reason. This is fine, just make
+ // sure we have an email address to show them.
+ email := user.UnconfirmedEmail
+ if email == "" {
+ // Already confirmed, take
+ // that address instead.
+ email = user.Email
+ }
+
+ // Serve page where user can click button
+ // to POST confirmation to same endpoint.
+ page := apiutil.WebPage{
+ Template: "confirm_email.tmpl",
+ Instance: instance,
+ Extra: map[string]any{
+ "email": email,
+ "username": user.Account.Username,
+ "token": token,
+ },
+ }
+
+ apiutil.TemplateWebPage(c, page)
+}
+
+func (m *Module) confirmEmailPOSTHandler(c *gin.Context) {
+ instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
+ if errWithCode != nil {
+ apiutil.WebErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
+ return
+ }
+
+ // Return instance we already got from the db,
+ // don't try to fetch it again when erroring.
+ instanceGet := func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode) {
+ return instance, nil
+ }
+
+ // We only serve text/html at this endpoint.
+ if _, err := apiutil.NegotiateAccept(c, apiutil.TextHTML); err != nil {
+ apiutil.WebErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), instanceGet)
+ return
+ }
+
+ // If there's no token in the query,
+ // just serve the 404 web handler.
+ token := c.Query("token")
+ if token == "" {
+ errWithCode := gtserror.NewErrorNotFound(errors.New(http.StatusText(http.StatusNotFound)))
+ apiutil.WebErrorHandler(c, errWithCode, instanceGet)
+ return
+ }
+
+ // Confirm email address for real this time.
user, errWithCode := m.processor.User().EmailConfirm(c.Request.Context(), token)
if errWithCode != nil {
apiutil.WebErrorHandler(c, errWithCode, instanceGet)
return
}
+ // Serve page informing user that their
+ // email address is now confirmed.
page := apiutil.WebPage{
- Template: "confirmed.tmpl",
+ Template: "confirmed_email.tmpl",
Instance: instance,
Extra: map[string]any{
"email": user.Email,
"username": user.Account.Username,
+ "token": token,
+ "approved": *user.Approved,
},
}