2024-07-14 21:26:34 +00:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
2024-08-14 10:36:43 +00:00
|
|
|
"net/mail"
|
2024-07-14 21:26:34 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func AsTimeP(t time.Time) *time.Time {
|
|
|
|
return &t
|
|
|
|
}
|
|
|
|
|
|
|
|
func AsInt32P(v int32) *int32 {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
|
|
|
func AsStringP(str string) *string {
|
|
|
|
return &str
|
|
|
|
}
|
2024-08-14 10:36:43 +00:00
|
|
|
|
|
|
|
func ValidPassword(str string) error {
|
|
|
|
if len(str) < 5 {
|
|
|
|
return ErrTooShortPassword
|
|
|
|
}
|
|
|
|
if len(str) > 70 {
|
|
|
|
return ErrTooLongPassword
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ValidEmail(str string) error {
|
|
|
|
emailAddress, err := mail.ParseAddress(str)
|
|
|
|
if err != nil || emailAddress.Address != str {
|
|
|
|
return ErrBadEmail
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ValidUsername(str string) error {
|
|
|
|
if len(str) < 5 {
|
|
|
|
return ErrTooShortUsername
|
|
|
|
}
|
|
|
|
if len(str) > 70 {
|
|
|
|
return ErrTooLongUsername
|
|
|
|
}
|
|
|
|
if err := ValidEmail(str); err == nil {
|
|
|
|
return ErrBadUsername
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|