mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-20 05:52:24 +00:00
Update Email Validation
This commit is contained in:
parent
2001d96148
commit
b4baf35ed8
1 changed files with 31 additions and 0 deletions
|
@ -2,7 +2,9 @@ package service
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -411,6 +413,12 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
email := clients[0].Email
|
||||
valid, err := validateEmail(email)
|
||||
if !valid {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var settings map[string]interface{}
|
||||
err = json.Unmarshal([]byte(data.Settings), &settings)
|
||||
if err != nil {
|
||||
|
@ -601,6 +609,12 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
|
|||
return false, err
|
||||
}
|
||||
|
||||
email := clients[0].Email
|
||||
valid, err := validateEmail(email)
|
||||
if !valid {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var settings map[string]interface{}
|
||||
err = json.Unmarshal([]byte(data.Settings), &settings)
|
||||
if err != nil {
|
||||
|
@ -2007,3 +2021,20 @@ func (s *InboundService) MigrateDB() {
|
|||
func (s *InboundService) GetOnlineClients() []string {
|
||||
return p.GetOnlineClients()
|
||||
}
|
||||
|
||||
func validateEmail(email string) (bool, error) {
|
||||
if strings.Contains(email, " ") {
|
||||
return false, errors.New("email contains spaces, please remove them")
|
||||
}
|
||||
|
||||
if email != strings.ToLower(email) {
|
||||
return false, errors.New("email contains uppercase letters, please convert to lowercase")
|
||||
}
|
||||
|
||||
emailPattern := `^[a-z0-9._-]+$`
|
||||
if !regexp.MustCompile(emailPattern).MatchString(email) {
|
||||
return false, errors.New("email contains invalid characters, please use only lowercase letters, digits, dots, dashes, and underscores")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue