Normalize Ethiopian phone inputs for user lookup, accept web Google client IDs for ID token login, and update the checkout integration guide for OTP and social sign-in. Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package repository
|
|
|
|
import "strings"
|
|
|
|
func normalizeEmail(email string) string {
|
|
return strings.ToLower(strings.TrimSpace(email))
|
|
}
|
|
|
|
// normalizePhone converts common Ethiopian phone inputs to canonical 251XXXXXXXXX form.
|
|
func normalizePhone(phone string) string {
|
|
digits := strings.Map(func(r rune) rune {
|
|
if r >= '0' && r <= '9' {
|
|
return r
|
|
}
|
|
return -1
|
|
}, strings.TrimSpace(phone))
|
|
if digits == "" {
|
|
return strings.TrimSpace(phone)
|
|
}
|
|
|
|
switch {
|
|
case strings.HasPrefix(digits, "251") && len(digits) >= 12:
|
|
return digits
|
|
case strings.HasPrefix(digits, "0") && len(digits) >= 10:
|
|
return "251" + digits[1:]
|
|
case (strings.HasPrefix(digits, "9") || strings.HasPrefix(digits, "7")) && len(digits) == 9:
|
|
return "251" + digits
|
|
case strings.HasPrefix(digits, "251"):
|
|
return digits
|
|
default:
|
|
return "251" + digits
|
|
}
|
|
}
|
|
|
|
func phoneLookupCandidates(phone string) []string {
|
|
normalized := normalizePhone(phone)
|
|
candidates := []string{normalized}
|
|
|
|
if strings.HasPrefix(normalized, "251") && len(normalized) > 3 {
|
|
local := "0" + normalized[3:]
|
|
if local != normalized {
|
|
candidates = append(candidates, local)
|
|
}
|
|
}
|
|
|
|
return candidates
|
|
}
|