email: Add option to require on sign-up

for #172
tailwind
Harvey Tindall 3 years ago
parent 9fff5781f4
commit 0fd4f516b1
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -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)

@ -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."
}
}
},

@ -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 }}";

@ -29,6 +29,7 @@
"errorMatrixVerification": "Matrix verification required.",
"errorInvalidPIN": "PIN is invalid.",
"errorUnknown": "Unknown error.",
"errorNoEmail": "Email required.",
"verified": "Account verified."
},
"validationStrings": {

@ -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();

@ -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()

Loading…
Cancel
Save