refactor(auth): extract timestamp validation to separate function
Move timestamp validation logic from handlers to ValidateTimeStamp function in auth.go to avoid code duplication and improve maintainability
This commit is contained in:
@@ -19,9 +19,9 @@ type TokenInfo struct {
|
||||
}
|
||||
|
||||
var (
|
||||
tokenMap = make(map[int]*TokenInfo)
|
||||
tokenMux sync.RWMutex
|
||||
tokenTTL = time.Hour
|
||||
tokenMap = make(map[int]*TokenInfo)
|
||||
tokenMux sync.RWMutex
|
||||
tokenTTL = time.Hour
|
||||
)
|
||||
|
||||
func GenerateToken(userID int) (string, error) {
|
||||
@@ -168,3 +168,11 @@ func isValidPassword(password string) bool {
|
||||
|
||||
return hasUpper && hasLower && hasDigit && hasSpecial
|
||||
}
|
||||
|
||||
func ValidateTimeStamp(timeStamp int64) error {
|
||||
currentTime := time.Now().UnixMilli()
|
||||
if !globalConfig.Debug && (currentTime-timeStamp > 3000 || timeStamp-currentTime > 3000) {
|
||||
return errors.New("timestamp out of valid range")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user