Skip to content

Commit

Permalink
[refactor] email verification method
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Oct 10, 2024
1 parent f1f5d32 commit 4b1c76e
Showing 1 changed file with 2 additions and 38 deletions.
40 changes: 2 additions & 38 deletions web/service/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package service

import (
"encoding/json"
"errors"
"fmt"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

4 comments on commit 4b1c76e

@saeed-54996
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍😍

@mehdikhody
Copy link
Contributor

@mehdikhody mehdikhody commented on 4b1c76e Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update just broke my application. why would you validate email address ? why just use lowercase ? please revert this changes, until then I have to use older versions. just let devs use what ever as email. email is optional in v2ray-core so why are you so strict about it at all ?

@Amirziplin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

درست شده ک ، من آخرین نسخه رو نصب کردم ، حتی با حروف فارسی هم مشکلی نداره

@mehdikhody
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I had the previous version, thanks you for this update then :D. I had some problems with white spaces that seems they are gone.
I'm Grateful.

Please sign in to comment.