summaryrefslogtreecommitdiff
path: root/internal/validate/formvalidation.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/validate/formvalidation.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/validate/formvalidation.go')
-rw-r--r--internal/validate/formvalidation.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/validate/formvalidation.go b/internal/validate/formvalidation.go
index b0332a572..3c16dd86e 100644
--- a/internal/validate/formvalidation.go
+++ b/internal/validate/formvalidation.go
@@ -348,3 +348,42 @@ func FilterContexts(contexts []apimodel.FilterContext) error {
}
return nil
}
+
+// CreateAccount checks through all the prerequisites for
+// creating a new account, according to the provided form.
+// If the account isn't eligible, an error will be returned.
+//
+// Side effect: normalizes the provided language tag for the user's locale.
+func CreateAccount(form *apimodel.AccountCreateRequest) error {
+ if form == nil {
+ return errors.New("form was nil")
+ }
+
+ if !config.GetAccountsRegistrationOpen() {
+ return errors.New("registration is not open for this server")
+ }
+
+ if err := Username(form.Username); err != nil {
+ return err
+ }
+
+ if err := Email(form.Email); err != nil {
+ return err
+ }
+
+ if err := Password(form.Password); err != nil {
+ return err
+ }
+
+ if !form.Agreement {
+ return errors.New("agreement to terms and conditions not given")
+ }
+
+ locale, err := Language(form.Locale)
+ if err != nil {
+ return err
+ }
+ form.Locale = locale
+
+ return SignUpReason(form.Reason, config.GetAccountsReasonRequired())
+}