45 lines
899 B
Go
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"
|
|
}
|