Proje: Okul Platform · Hub: Okul Platform — Domain

OtpCodeService

app/Services/Bases/OtpCodeService.php

generateOtp() Akışı

  1. Normalizasyon: E-posta → unchanged, telefon → getPhoneNakedWithDigit_11()

  2. IP Rate Limit: validateIpRateLimit() — Çok fazla istek engellemek için

  3. UserContact Kontrolü:

    • Kayıt yok → OtpUserNotFoundException
    • Birden fazla kullanıcıya bağlı → OtpDuplicateContactException
    • Tek kullanıcı → OTP oluştur
  4. OTP Oluşturma: Cache::lock() ile concurrent request koruması (lock timeout → LockTimeoutException)

  5. OTP Gönderme: sendOtp()OtpCodeType::getJobByType()SendOtpCodeSmsJob veya SendOtpCodeEmailJob

verifyOtp() Akışı

  1. findActiveByValue() → Aktif OTP bul
  2. Yok → expired exception
  3. isValid() → max_attempts kontrolü
  4. Hash::check(code, otp.code) → Bcrypt ile kod doğrulama
  5. Yanlış → incrementAttempt() + kalan deneme sayısını bildir
  6. Sıfır kalan → “maximum_exceeded”
  7. Doğru → markAsUsed()

Güvenlik Özellikleri

  • OTP kod hash’lenmiş saklanır (Bcrypt)
  • IP bazlı rate limiting
  • Cache lock ile concurrent istek önleme
  • Max attempts ile brute force engeli

temizlik

cleanExpiredOtpCodes()CleanExpiredOtpCodesCommand tarafından çağrılır.