Proje: Okul Platform · Hub: Okul Platform — Domain

OtpCode Model

Alanlar:

  • user_id → User (opsiyonel — kayıtsız kullanıcı da OTP alabilir)
  • value — E-posta veya telefon numarası
  • type → OtpCodeType (phone veya email)
  • code — OTP kodu (hidden - response’da gösterilmez)
  • expires_at — Son kullanma tarihi
  • verified_at — Doğrulama tarihi
  • attempt_count — Hatalı deneme sayısı
  • ip_address, user_agent — İstek bilgileri
  • ref — Referans (neden OTP alındı)

Geçerlilik Kontrolleri

$otp->isValid()   // expire olmamış + max_attempts aşılmamış
$otp->isExpired() // expires_at geçmişte mi

Max attempts: config('app_settings.otp_code.max_attempts')

Scope’lar

OtpCode::query()->active()   // verified olmamış + expire olmamış
OtpCode::query()->expired()  // expires_at geçmiş

OtpCodeType Enum

phone → SendOtpCodeSmsJob  (Infobip üzerinden SMS)
email → SendOtpCodeEmailJob (mail üzerinden)

OTP Exceptions

OtpCodeException              — Genel OTP hatası
OtpRateLimitExceededException — Rate limit (çok fazla deneme)
OtpDuplicateContactException  — Aynı telefon/email birden fazla hesapta
OtpUserNotFoundException      — Kullanıcı bulunamadı

Temizlik

CleanExpiredOtpCodesCommand — Süresi dolmuş OTP kodlarını siler.