UPDATE: Auth module, User module
Some checks failed
Build and Release / release (push) Failing after 1m25s
Some checks failed
Build and Release / release (push) Failing after 1m25s
This commit is contained in:
39
pkg/constants/regex.go
Normal file
39
pkg/constants/regex.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var (
|
||||
// Password components (Go-compatible)
|
||||
hasUpper = regexp.MustCompile(`[A-Z]`)
|
||||
hasLower = regexp.MustCompile(`[a-z]`)
|
||||
hasNumber = regexp.MustCompile(`\d`)
|
||||
hasSpecial = regexp.MustCompile(`[!@#$%^&*()_+{}|:<>?~-]`)
|
||||
|
||||
// Standard Regexes
|
||||
PHONE_NUMBER_REGEX = regexp.MustCompile(`^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$`)
|
||||
EMAIL_REGEX = regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
|
||||
YOUTUBE_VIDEO_ID_REGEX = regexp.MustCompile(`(?:\/|v=|\/v\/|embed\/|watch\?v=|watch\?.+&v=)([\w-]{11})`)
|
||||
BANK_INPUT = regexp.MustCompile(`[__]{2,}`)
|
||||
)
|
||||
|
||||
func ValidatePassword(password string) error {
|
||||
if len(password) < 8 {
|
||||
return errors.New("password must be at least 8 characters long")
|
||||
}
|
||||
if !hasUpper.MatchString(password) {
|
||||
return errors.New("password must contain at least one uppercase letter")
|
||||
}
|
||||
if !hasLower.MatchString(password) {
|
||||
return errors.New("password must contain at least one lowercase letter")
|
||||
}
|
||||
if !hasNumber.MatchString(password) {
|
||||
return errors.New("password must contain at least one number")
|
||||
}
|
||||
if !hasSpecial.MatchString(password) {
|
||||
return errors.New("password must contain at least one special character")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
39
pkg/constants/role.go
Normal file
39
pkg/constants/role.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package constants
|
||||
|
||||
type Role string
|
||||
|
||||
const (
|
||||
ADMIN Role = "ADMIN"
|
||||
MOD Role = "MOD"
|
||||
USER Role = "USER"
|
||||
HISTORIAN Role = "HISTORIAN"
|
||||
BANNED Role = "BANNED"
|
||||
)
|
||||
|
||||
func (r Role) String() string {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
func (r Role) Compare(other Role) bool {
|
||||
return r == other
|
||||
}
|
||||
|
||||
func (r Role) IsValid() bool {
|
||||
return CheckValidRole(r)
|
||||
}
|
||||
|
||||
func CheckValidRole(r Role) bool {
|
||||
return r == ADMIN || r == MOD || r == HISTORIAN || r == USER || r == BANNED
|
||||
}
|
||||
|
||||
|
||||
func ParseRole(s string) (Role, bool) {
|
||||
r := Role(s)
|
||||
if CheckValidRole(r) {
|
||||
return r, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
func (r Role) ToSlice() []Role {
|
||||
return []Role{r}
|
||||
}
|
||||
6
pkg/constants/sream.go
Normal file
6
pkg/constants/sream.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
StreamEmailName = "stream:email_tasks"
|
||||
GroupEmailName = "email_workers_group"
|
||||
)
|
||||
35
pkg/constants/status.go
Normal file
35
pkg/constants/status.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package constants
|
||||
|
||||
type StatusType int16
|
||||
|
||||
const (
|
||||
StatusPending StatusType = 1
|
||||
StatusApproved StatusType = 2
|
||||
StatusRejected StatusType = 3
|
||||
)
|
||||
|
||||
func (t StatusType) String() string {
|
||||
switch t {
|
||||
case StatusPending:
|
||||
return "PENDING"
|
||||
case StatusApproved:
|
||||
return "APPROVED"
|
||||
case StatusRejected:
|
||||
return "REJECT"
|
||||
default:
|
||||
return "UNKNOWN"
|
||||
}
|
||||
}
|
||||
|
||||
func ParseStatusType(v int16) StatusType {
|
||||
switch v {
|
||||
case 1:
|
||||
return StatusPending
|
||||
case 2:
|
||||
return StatusApproved
|
||||
case 3:
|
||||
return StatusRejected
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
11
pkg/constants/task.go
Normal file
11
pkg/constants/task.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package constants
|
||||
|
||||
type TaskType string
|
||||
|
||||
const (
|
||||
TaskTypeSendEmailOTP TaskType = "SEND_EMAIL_OTP"
|
||||
)
|
||||
|
||||
func (t TaskType) String() string {
|
||||
return string(t)
|
||||
}
|
||||
13
pkg/constants/time.go
Normal file
13
pkg/constants/time.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package constants
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
TokenCooldownDuration = 1 * time.Minute
|
||||
TokenExpirationDuration = 20 * time.Minute
|
||||
NormalCacheDuration = 15 * time.Minute
|
||||
ListCacheDuration = 10 * time.Minute
|
||||
AccessTokenDuration = 15 * time.Minute
|
||||
RefreshTokenDuration = 7 * 24 * time.Hour
|
||||
TokenVerifiedDuration = 10 * time.Minute
|
||||
)
|
||||
59
pkg/constants/token.go
Normal file
59
pkg/constants/token.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package constants
|
||||
|
||||
type TokenType int16
|
||||
|
||||
const (
|
||||
TokenPasswordReset TokenType = 1
|
||||
TokenEmailVerify TokenType = 2
|
||||
TokenMagicLink TokenType = 3
|
||||
TokenRefreshToken TokenType = 4
|
||||
)
|
||||
|
||||
func (t TokenType) String() string {
|
||||
switch t {
|
||||
case TokenPasswordReset:
|
||||
return "PASSWORD_RESET"
|
||||
case TokenEmailVerify:
|
||||
return "EMAIL_VERIFY"
|
||||
case TokenMagicLink:
|
||||
return "LOGIN_MAGIC_LINK"
|
||||
case TokenRefreshToken:
|
||||
return "REFRESH_TOKEN"
|
||||
default:
|
||||
return "UNKNOWN"
|
||||
}
|
||||
}
|
||||
|
||||
func (t TokenType) Value() int16 {
|
||||
return int16(t)
|
||||
}
|
||||
|
||||
func ParseTokenType(v int16) TokenType {
|
||||
switch v {
|
||||
case 1:
|
||||
return TokenPasswordReset
|
||||
case 2:
|
||||
return TokenEmailVerify
|
||||
case 3:
|
||||
return TokenMagicLink
|
||||
case 4:
|
||||
return TokenRefreshToken
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func ParseTokenTypeFromString(s string) TokenType {
|
||||
switch s {
|
||||
case "PASSWORD_RESET":
|
||||
return TokenPasswordReset
|
||||
case "EMAIL_VERIFY":
|
||||
return TokenEmailVerify
|
||||
case "LOGIN_MAGIC_LINK":
|
||||
return TokenMagicLink
|
||||
case "REFRESH_TOKEN":
|
||||
return TokenRefreshToken
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
35
pkg/constants/verify.go
Normal file
35
pkg/constants/verify.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package constants
|
||||
|
||||
type VerifyType int16
|
||||
|
||||
const (
|
||||
VerifyIdCard VerifyType = 1
|
||||
VerifyEducation VerifyType = 2
|
||||
VerifyExpert VerifyType = 3
|
||||
)
|
||||
|
||||
func (t VerifyType) String() string {
|
||||
switch t {
|
||||
case VerifyIdCard:
|
||||
return "ID_CARD"
|
||||
case VerifyEducation:
|
||||
return "EDUCATION"
|
||||
case VerifyExpert:
|
||||
return "EXPERT"
|
||||
default:
|
||||
return "UNKNOWN"
|
||||
}
|
||||
}
|
||||
|
||||
func ParseVerifyType(v int16) VerifyType {
|
||||
switch v {
|
||||
case 1:
|
||||
return VerifyIdCard
|
||||
case 2:
|
||||
return VerifyEducation
|
||||
case 3:
|
||||
return VerifyExpert
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user