Files
projet_gestion_commande/backend/gestion/utils/auth.go
T
Nuxgrid 12a7facc45
Backend - Build & Lint / build (push) Failing after 16m17s
chore: build
2026-07-08 21:54:00 +02:00

45 lines
899 B
Go

package utils
import (
"crypto/rand"
"encoding/hex"
"regexp"
"strings"
"github.com/gin-gonic/gin"
)
func GenerateSessionID() string {
bytes := make([]byte, 16)
rand.Read(bytes)
return hex.EncodeToString(bytes)
}
func ValidatePhoneNumber(phone string) bool {
clean := regexp.MustCompile(`[\s\-\(\)]`).ReplaceAllString(phone, "")
validFormat := regexp.MustCompile(`^(\+33|0)[1-9]\d{8}$`)
return validFormat.MatchString(clean)
}
func NormalizePhoneNumber(phone string) string {
clean := regexp.MustCompile(`[\s\-\(\)]`).ReplaceAllString(phone, "")
if strings.HasPrefix(clean, "0") {
return "+33" + clean[1:]
}
return clean
}
func CheckRoleAdmin(c *gin.Context, role string) bool {
return role == "admin"
}
func CheckRoleClient(c *gin.Context, role string) bool {
return role == "client"
}
func CheckRoleCabine(c *gin.Context, role string) bool {
return role == "cabine"
}