diff --git a/api.go b/api.go index e04f2b6..2e33509 100644 --- a/api.go +++ b/api.go @@ -644,6 +644,11 @@ func (app *appContext) NewUser(gc *gin.Context) { gc.JSON(200, validation) return } + if emailEnabled && app.config.Section("email").Key("required").MustBool(false) && !strings.Contains(req.Email, "@") { + app.info.Printf("%s: New user failed: Email Required", req.Code) + respond(400, "errorNoEmail", gc) + return + } f, success := app.newUser(req, false) if !success { f(gc) diff --git a/config/config-base.json b/config/config-base.json index 382e9ea..a4e5690 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -458,6 +458,15 @@ "type": "bool", "value": false, "description": "Send emails as plain text instead of HTML." + }, + "required": { + "name": "Require on sign-up", + "required": false, + "requires_restart": false, + "depends_true": "method", + "type": "bool", + "value": false, + "description": "Require an email address on sign-up." } } }, diff --git a/html/form-base.html b/html/form-base.html index af2d41a..4edb119 100644 --- a/html/form-base.html +++ b/html/form-base.html @@ -17,6 +17,7 @@ window.telegramEnabled = {{ .telegramEnabled }}; window.telegramRequired = {{ .telegramRequired }}; window.telegramPIN = "{{ .telegramPIN }}"; + window.emailRequired = {{ .emailRequired }}; window.discordEnabled = {{ .discordEnabled }}; window.discordRequired = {{ .discordRequired }}; window.discordPIN = "{{ .discordPIN }}"; diff --git a/lang/form/en-us.json b/lang/form/en-us.json index cec4319..c504cb7 100644 --- a/lang/form/en-us.json +++ b/lang/form/en-us.json @@ -29,6 +29,7 @@ "errorMatrixVerification": "Matrix verification required.", "errorInvalidPIN": "PIN is invalid.", "errorUnknown": "Unknown error.", + "errorNoEmail": "Email required.", "verified": "Account verified." }, "validationStrings": { diff --git a/ts/form.ts b/ts/form.ts index c31cbe5..0ebac9e 100644 --- a/ts/form.ts +++ b/ts/form.ts @@ -29,6 +29,7 @@ interface formWindow extends Window { userExpiryHours: number; userExpiryMinutes: number; userExpiryMessage: string; + emailRequired: boolean; } loadLangSelector("form"); @@ -39,6 +40,7 @@ window.animationEvent = whichAnimationEvent(); window.successModal = new Modal(document.getElementById("modal-success"), true); + var telegramVerified = false; if (window.telegramEnabled) { window.telegramModal = new Modal(document.getElementById("modal-telegram"), window.telegramRequired); @@ -230,6 +232,18 @@ if (!window.usernameEnabled) { usernameField.parentElement.remove(); usernameFie const passwordField = document.getElementById("create-password") as HTMLInputElement; const rePasswordField = document.getElementById("create-reenter-password") as HTMLInputElement; +if (window.emailRequired) { + emailField.addEventListener("keyup", () => { + if (emailField.value.includes("@")) { + submitButton.disabled = false; + submitSpan.removeAttribute("disabled"); + } else { + submitButton.disabled = true; + submitSpan.setAttribute("disabled", ""); + } + }); +} + var requirements = initValidator(passwordField, rePasswordField, submitButton, submitSpan) interface respDTO { @@ -302,7 +316,7 @@ const create = (event: SubmitEvent) => { }, true, (req: XMLHttpRequest) => { if (req.readyState == 4) { toggleLoader(submitSpan); - if (req.status == 401) { + if (req.status == 401 || req.status == 400) { if (req.response["error"] as string) { if (req.response["error"] == "confirmEmail") { window.confirmationModal.show(); diff --git a/views.go b/views.go index 4356564..dde64fa 100644 --- a/views.go +++ b/views.go @@ -358,6 +358,7 @@ func (app *appContext) InviteProxy(gc *gin.Context) { "telegramEnabled": telegram, "discordEnabled": discord, "matrixEnabled": matrix, + "emailRequired": app.config.Section("email").Key("required").MustBool(false), } if telegram { data["telegramPIN"] = app.telegram.NewAuthToken()