Add forgot-password SMS reset, client/staff user lists, and regenerate Swagger.

Fold follow-up migrations into init, expose GET /users/clients and /users/staff, and refresh seed data.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-14 16:42:47 +05:00
parent 5e3c46da83
commit 514b9ca5fc
24 changed files with 1477 additions and 473 deletions

View File

@@ -2,6 +2,7 @@ package auth
import (
"fmt"
"strconv"
"strings"
"unicode"
)
@@ -16,19 +17,30 @@ func onlyDigits(s string) string {
return b.String()
}
// NormalizePhone accepts Turkmen numbers in common local forms and
// returns +993 6X XX XX XX.
// NormalizePhone strips a leading +993 / 993 country code, then checks
// that the remaining local number is 8 digits with prefix 61–65 or 71–72.
// It returns +993 XX XX XX XX.
func NormalizePhone(raw string) (string, error) {
digits := onlyDigits(raw)
switch {
case strings.HasPrefix(digits, "993") && len(digits) == 11:
if strings.HasPrefix(digits, "993") {
digits = digits[3:]
case len(digits) == 9 && digits[0] == '8':
} else if len(digits) == 9 && digits[0] == '8' {
digits = digits[1:]
}
if len(digits) != 8 {
return "", ErrInvalidPhone
}
if !validMobilePrefix(digits[:2]) {
return "", ErrInvalidPhone
}
return fmt.Sprintf("+993 %s %s %s %s", digits[0:2], digits[2:4], digits[4:6], digits[6:8]), nil
}
func validMobilePrefix(prefix string) bool {
n, err := strconv.Atoi(prefix)
if err != nil {
return false
}
return (n >= 61 && n <= 65) || (n >= 71 && n <= 72)
}