fix: email comments are removed from email addresses (#9074)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9074
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2025-08-30 13:15:30 +02:00
commit 1b13fda06b
9 changed files with 99 additions and 21 deletions

View file

@ -149,7 +149,7 @@ func CreateUser(ctx *context.APIContext) {
return
}
if !validation.IsEmailDomainAllowed(u.Email) {
if _, ok := validation.IsEmailDomainAllowed(u.Email); !ok {
ctx.Resp.Header().Add("X-Gitea-Warning", fmt.Sprintf("the domain of user email %s conflicts with EMAIL_DOMAIN_ALLOWLIST or EMAIL_DOMAIN_BLOCKLIST", u.Email))
}
@ -235,7 +235,7 @@ func EditUser(ctx *context.APIContext) {
return
}
if !validation.IsEmailDomainAllowed(*form.Email) {
if _, ok := validation.IsEmailDomainAllowed(*form.Email); !ok {
ctx.Resp.Header().Add("X-Gitea-Warning", fmt.Sprintf("the domain of user email %s conflicts with EMAIL_DOMAIN_ALLOWLIST or EMAIL_DOMAIN_BLOCKLIST", *form.Email))
}
}

View file

@ -201,7 +201,7 @@ func NewUserPost(ctx *context.Context) {
return
}
if !validation.IsEmailDomainAllowed(u.Email) {
if _, ok := validation.IsEmailDomainAllowed(u.Email); !ok {
ctx.Flash.Warning(ctx.Tr("form.email_domain_is_not_allowed", u.Email))
}
@ -421,7 +421,7 @@ func EditUserPost(ctx *context.Context) {
}
return
}
if !validation.IsEmailDomainAllowed(form.Email) {
if _, ok := validation.IsEmailDomainAllowed(form.Email); !ok {
ctx.Flash.Warning(ctx.Tr("form.email_domain_is_not_allowed", form.Email))
}
}

View file

@ -453,7 +453,10 @@ func SignUpPost(ctx *context.Context) {
return
}
if !form.IsEmailDomainAllowed() {
if emailValid, ok := form.IsEmailDomainAllowed(); !emailValid {
ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tplSignUp, form)
return
} else if !ok {
ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplSignUp, &form)
return
}

View file

@ -226,7 +226,10 @@ func LinkAccountPostRegister(ctx *context.Context) {
}
}
if !form.IsEmailDomainAllowed() {
if emailValid, ok := form.IsEmailDomainAllowed(); !emailValid {
ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tplSignUp, form)
return
} else if !ok {
ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplLinkAccount, &form)
return
}