From 9fb8a78f91adffd5f4d28df1270e407c25a7a16e Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:45:53 +0200 Subject: [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 --- internal/validate/formvalidation.go | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'internal/validate/formvalidation.go') 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()) +} -- cgit v1.2.3