1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-10-31 15:30:10 +00:00

email: Add option to require on sign-up

for #172
This commit is contained in:
Harvey Tindall 2021-12-20 18:44:31 +00:00
parent 9fff5781f4
commit 0fd4f516b1
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
6 changed files with 32 additions and 1 deletions

5
api.go
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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