mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user