Initial commit: dating app backend (Go/Gin/GORM/Postgres)

Phone+OTP auth, staged onboarding, admin approval workflow, and a
full discovery/swipe/match/chat system with photo upload and
approximate distance (haversine) based on user location.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 23:23:47 +03:30
commit 2823fb45f5
49 changed files with 4582 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package utils
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"errors"
"math/rand"
"regexp"
)
var phoneRegex = regexp.MustCompile(`^09\d{9}$`)
// ValidatePhone فقط شماره موبایل ایرانی با فرمت 09XXXXXXXXX را قبول می‌کند
func ValidatePhone(phone string) error {
if !phoneRegex.MatchString(phone) {
return errors.New("شماره موبایل باید ۱۱ رقم باشد و با 09 شروع شود")
}
return nil
}
// GenerateOTP یک کد عددی تصادفی با طول مشخص می‌سازد
func GenerateOTP(length int) string {
digits := "0123456789"
b := make([]byte, length)
for i := range b {
b[i] = digits[rand.Intn(len(digits))]
}
return string(b)
}
// HashOTP کد OTP را با HMAC-SHA256 هش می‌کند تا در دیتابیس به‌صورت خام ذخیره نشود
func HashOTP(otp, secretKey string) string {
h := hmac.New(sha256.New, []byte(secretKey))
h.Write([]byte(otp))
return hex.EncodeToString(h.Sum(nil))
}