Porównaj commity

...

2 Commity

Autor SHA1 Wiadomość Data
Xeronith 3e0ec9db94 chore(project): ⬆️ upgrade dependencies 2023-07-12 09:55:46 +03:30
Xeronith 9df2bd01bd feat(project): 🦺 improve validation 2023-07-12 09:55:07 +03:30
8 zmienionych plików z 22 dodań i 33 usunięć

Wyświetl plik

@ -7,7 +7,7 @@ import (
)
func ResetPassword(x IDispatcher, usernameOrEmail string) (IResetPasswordResult, error) {
isEmail := x.MatchString(EMAIL, usernameOrEmail)
isEmail := REGEXP_EMAIL.MatchString(usernameOrEmail)
if !isEmail && !UsernameIsValid(usernameOrEmail) {
return nil, ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -1,11 +1,7 @@
package validators
import (
"regexp"
. "github.com/reiver/greatape/components/constants"
)
import . "github.com/reiver/greatape/components/constants"
func EmailIsValid(input string) bool {
return regexp.MustCompile(EMAIL).MatchString(input)
return REGEXP_EMAIL.MatchString(input)
}

Wyświetl plik

@ -1,13 +1,9 @@
package validators
import (
"regexp"
. "github.com/reiver/greatape/components/constants"
)
import . "github.com/reiver/greatape/components/constants"
func UsernameIsValid(username string) bool {
if !regexp.MustCompile(USERNAME).MatchString(username) {
if !REGEXP_USERNAME.MatchString(username) {
return false
}

Wyświetl plik

@ -1,11 +1,7 @@
package validators
import (
"regexp"
. "github.com/reiver/greatape/components/constants"
)
import . "github.com/reiver/greatape/components/constants"
func WebfingerIsValid(webfinger string) bool {
return regexp.MustCompile(WEBFINGER).MatchString(webfinger)
return REGEXP_WEBFINGER.MatchString(webfinger)
}

Wyświetl plik

@ -1,11 +0,0 @@
package constants
// noinspection GoSnakeCaseUsage, GoUnusedConst
const (
USERNAME = "^[a-z0-9_\\.]{5,16}$"
PASSWORD = "^.{6,}$"
PHONE_NUMBER = "^9\\d{9}$"
URL = "^(?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$"
EMAIL = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"
WEBFINGER = "^acct:[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"
)

Wyświetl plik

@ -0,0 +1,12 @@
package constants
import "regexp"
var (
REGEXP_USERNAME = regexp.MustCompile(`^[a-z0-9_\.]{5,16}$`)
REGEXP_PASSWORD = regexp.MustCompile(`^.{6,}$`)
REGEXP_PHONE_NUMBER = regexp.MustCompile(`^9\d{9}$`)
REGEXP_URL = regexp.MustCompile(`^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/|\/|\/\/)?[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$`)
REGEXP_EMAIL = regexp.MustCompile(`^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$`)
REGEXP_WEBFINGER = regexp.MustCompile(`^acct:[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$`)
)

2
go.mod
Wyświetl plik

@ -8,7 +8,7 @@ require (
github.com/robfig/cron v1.2.0
github.com/sendgrid/sendgrid-go v3.12.0+incompatible
github.com/valyala/fastjson v1.6.4
github.com/xeronith/diamante v1.15.3
github.com/xeronith/diamante v1.15.5
google.golang.org/protobuf v1.28.1
)

4
go.sum
Wyświetl plik

@ -64,8 +64,8 @@ github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLr
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/xeronith/diamante v1.15.3 h1:ASks0WIidHUOhFVBs4HLpLEwFLz5/WGtt1AO9pYjX+o=
github.com/xeronith/diamante v1.15.3/go.mod h1:7kgdoRJVrQvML7Z9BT6di3XU1o2eTeE0hbwy66dMOrA=
github.com/xeronith/diamante v1.15.5 h1:/VnxmLiG+CFqwMTphjgp2juQcpu0cVxD3DO8bj4rwOQ=
github.com/xeronith/diamante v1.15.5/go.mod h1:7kgdoRJVrQvML7Z9BT6di3XU1o2eTeE0hbwy66dMOrA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=