feat: add regex to restrict Email addresses in OAuth provider (#3465)

* feat: support use regex expression to limit email receiver address

* feat: limit in correct pos

* feat: promote code format

* feat: promote code format

* fix: fix linter issue
This commit is contained in:
DacongDA
2025-01-02 00:00:57 +08:00
committed by GitHub
parent b57b64fc36
commit 888a6f2feb
3 changed files with 42 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import (
"io"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
@ -617,6 +618,17 @@ func (c *ApiController) Login() {
c.ResponseError(fmt.Sprintf(c.T("auth:Failed to login in: %s"), err.Error()))
return
}
if provider.EmailRegex != "" {
reg, err := regexp.Compile(provider.EmailRegex)
if err != nil {
c.ResponseError(fmt.Sprintf(c.T("auth:Failed to login in: %s"), err.Error()))
return
}
if !reg.MatchString(userInfo.Email) {
c.ResponseError(fmt.Sprintf(c.T("check:Email is invalid")))
}
}
}
if authForm.Method == "signup" {