Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlireza Ahmadi <alireza7@gmail.com>2024-10-10 18:32:50 +0300
committerAlireza Ahmadi <alireza7@gmail.com>2024-10-10 18:32:50 +0300
commit4b1c76e97252c5bcc7a9ee16b8bd0dde693cabbb (patch)
treea97d52b2fa3d0abad1a3319fdcff391cec780c3d /web/service
parentf1f5d323e820e3839f3d400bbcf0a35db916aa2a (diff)
[refactor] email verification method
Diffstat (limited to 'web/service')
-rw-r--r--web/service/inbound.go40
1 files changed, 2 insertions, 38 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 822a4e8d..1450dd57 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -2,9 +2,7 @@ package service
import (
"encoding/json"
- "errors"
"fmt"
- "regexp"
"strconv"
"strings"
"time"
@@ -101,8 +99,9 @@ func (s *InboundService) getAllEmails() ([]string, error) {
}
func (s *InboundService) contains(slice []string, str string) bool {
+ lowerStr := strings.ToLower(str)
for _, s := range slice {
- if s == str {
+ if strings.ToLower(s) == lowerStr {
return true
}
}
@@ -414,12 +413,6 @@ 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 {
@@ -610,12 +603,6 @@ 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 {
@@ -2022,26 +2009,3 @@ 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")
- }
-
- nonEnglishPattern := `[^\x00-\x7F]`
- if regexp.MustCompile(nonEnglishPattern).MatchString(email) {
- return false, errors.New("email contains non-English characters, please use only English")
- }
-
- emailPattern := `^[a-z0-9@._-]+$`
- if !regexp.MustCompile(emailPattern).MatchString(email) {
- return false, errors.New("email contains invalid characters, please use only lowercase letters, digits, and @._-")
- }
-
- return true, nil
-}