feat: implement the enforcement for new invitation page (#2628)

Added new invitation code implementation
This commit is contained in:
HGZ-20
2024-01-22 02:25:13 +08:00
committed by GitHub
parent de2932b5fb
commit d7c40459c0
30 changed files with 306 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import (
"fmt"
"net/mail"
"regexp"
"strings"
"github.com/nyaruka/phonenumbers"
)
@ -53,6 +54,23 @@ func IsPhoneAllowInRegin(countryCode string, allowRegions []string) bool {
return ContainsString(allowRegions, countryCode)
}
func IsRegexp(s string) (bool, error) {
if _, err := regexp.Compile(s); err != nil {
return false, err
}
return regexp.QuoteMeta(s) != s, nil
}
func IsInvitationCodeMatch(pattern string, invitationCode string) (bool, error) {
if !strings.HasPrefix(pattern, "^") {
pattern = "^" + pattern
}
if !strings.HasSuffix(pattern, "$") {
pattern = pattern + "$"
}
return regexp.MatchString(pattern, invitationCode)
}
func GetE164Number(phone string, countryCode string) (string, bool) {
phoneNumber, _ := phonenumbers.Parse(phone, countryCode)
return phonenumbers.Format(phoneNumber, phonenumbers.E164), phonenumbers.IsValidNumber(phoneNumber)