mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-01 10:00:19 +08:00
feat: implement the enforcement for new invitation page (#2628)
Added new invitation code implementation
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user