Files
dj52/COPILOT_MEMORY.md
Beyhan Oğur ec28a2024d first commit
2026-04-26 22:22:29 +03:00

7.1 KiB
Raw Blame History

Copilot Memory - Django Auth System Development

Bu dosya, Django 6.0 projemizde Custom User + Djoser + JWT + Social Auth sisteminin geliştirilme sürecini takip eder.


2025-12-12T21:35:00Z

Değişiklik Özeti: İlk Kurulum - Custom User Model ve Auth Sistemi Temeli

Tamamlanan İşler:

  1. Custom User Model Oluşturuldu (accounts/models.py)

    • CustomUser modeli: Email tabanlı authentication (username yok)
    • CustomUserManager: create_user ve create_superuser metodları
    • Alanlar: email (unique), first_name, last_name, is_staff, is_active, date_joined
    • USERNAME_FIELD = "email"
  2. Admin Panel Konfigürasyonu (accounts/admin.py)

    • CustomUserAdmin sınıfı ile Django admin'de custom user yönetimi
    • List display, filters, search fields yapılandırıldı
  3. Serializers Oluşturuldu (accounts/serializers.py)

    • CustomUserCreateSerializer: Register için, is_active=False set eder
    • CustomUserSerializer: User profil bilgileri için
    • SocialLoginSerializer: Social auth için provider + access_token
  4. Social Auth Pipeline (accounts/pipeline.py)

    • activate_user fonksiyonu: Social login ile gelen kullanıcıları otomatik aktif eder
    • Normal register: is_active=False (email aktivasyon gerekli)
    • Social register: is_active=True (direkt aktif)
  5. Social Login View (accounts/views.py)

    • SocialLoginView: Provider token'ı doğrular, user oluşturur/bulur, JWT döner
    • Desteklenen provider'lar: google-oauth2, github, facebook
    • Error handling: AuthForbidden, AuthException, genel hatalar
  6. Settings.py Tam Konfigürasyonu (core/settings.py)

    • AUTH_USER_MODEL = 'accounts.CustomUser'
    • INSTALLED_APPS: rest_framework, rest_framework_simplejwt, djoser, corsheaders, social_django, accounts
    • REST_FRAMEWORK: JWT authentication, throttling (100/hour anon, 1000/hour user)
    • SIMPLE_JWT: 60 min access, 7 days refresh, token rotation, blacklist
    • DJOSER: Email activation, custom serializers, password reset
    • EMAIL: MailPit (localhost:1025) dev için, production için SMTP placeholder
    • CORS: localhost:3000, 5173, 8080 (Nuxt/Next/Vue için)
    • SOCIAL_AUTH: Google, GitHub, Facebook backends + custom pipeline
  7. Email Templates Oluşturuldu (templates/email/)

    • activation_email.html / .txt: Hesap aktivasyon emaili
    • confirmation_email.html / .txt: Aktivasyon başarılı emaili
    • password_reset_email.html / .txt: Şifre sıfırlama emaili
    • Modern, responsive HTML tasarım + plain text alternatifi
  8. URL Routing (accounts/urls.py)

    • Djoser endpoints: /api/v1/auth/users/ (register), /api/v1/auth/users/activation/ (activate)
    • JWT endpoints: /api/v1/auth/jwt/create/ (login), /api/v1/auth/jwt/refresh/
    • Social auth: /api/v1/auth/social/<provider>/
    • Python Social Auth URLs: /api/v1/social/
  9. Database Migrations

    • accounts/migrations/0001_initial.py: CustomUser model
    • social_django migrations: Social auth tabloları
    • Tüm migration'lar başarıyla uygulandı (migrate completed)

📁 Değiştirilen/Oluşturulan Dosyalar:

  • accounts/models.py (yeni)
  • accounts/admin.py (güncellendi)
  • accounts/serializers.py (yeni)
  • accounts/pipeline.py (yeni)
  • accounts/views.py (güncellendi)
  • accounts/urls.py (güncellendi)
  • accounts/migrations/0001_initial.py (oluşturuldu)
  • core/settings.py (kapsamlı güncelleme)
  • templates/email/activation_email.html (yeni)
  • templates/email/activation_email.txt (yeni)
  • templates/email/confirmation_email.html (yeni)
  • templates/email/confirmation_email.txt (yeni)
  • templates/email/password_reset_email.html (yeni)
  • templates/email/password_reset_email.txt (yeni)

🎯 Sistem Özellikleri:

Authentication Akışları:

  1. Normal Register (Email/Password):

    POST /api/v1/auth/users/
    Body: { "email", "password", "re_password", "first_name", "last_name" }
    → User oluşturulur (is_active=False)
    → Aktivasyon emaili gönderilir
    → POST /api/v1/auth/users/activation/ { "uid", "token" }
    → is_active=True olur
    → POST /api/v1/auth/jwt/create/ { "email", "password" }
    → JWT tokens alınır
    
  2. Social Login:

    POST /api/v1/auth/social/google-oauth2/
    Body: { "access_token": "..." }
    → Provider'dan user bilgisi alınır
    → User bulunur/oluşturulur (is_active=True)
    → JWT tokens direkt döner
    
  3. Login:

    POST /api/v1/auth/jwt/create/
    Body: { "email", "password" }
    → Access + Refresh token döner
    
  4. Token Refresh:

    POST /api/v1/auth/jwt/refresh/
    Body: { "refresh": "..." }
    → Yeni access token döner
    

⚙️ Yapılandırma Gereksinimleri:

Environment Variables (Production için):

# Email
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-app-password
DEFAULT_FROM_EMAIL=noreply@yourdomain.com

# Social Auth - Google
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=your-google-client-id
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=your-google-client-secret

# Social Auth - GitHub
SOCIAL_AUTH_GITHUB_KEY=your-github-client-id
SOCIAL_AUTH_GITHUB_SECRET=your-github-client-secret

# Social Auth - Facebook
SOCIAL_AUTH_FACEBOOK_KEY=your-facebook-app-id
SOCIAL_AUTH_FACEBOOK_SECRET=your-facebook-app-secret

Development Tools:

  • MailPit: localhost:1025 (SMTP), localhost:8025 (Web UI)
  • Database: SQLite (db.sqlite3)

📝 Next Steps:

  1. Testing (Yüksek Öncelik):

    • Unit tests: Register → is_active=False check
    • Unit tests: Activation → is_active=True check
    • Unit tests: Login → aktif/inaktif user scenarios
    • Unit tests: Social login → user creation + JWT response
    • Integration tests: Full auth flow
  2. Dokümantasyon:

    • AUTH.md oluştur: Tüm endpoint'ler, request/response örnekleri
    • Frontend entegrasyon kılavuzu (Nuxt.js + Next.js)
    • Environment variables dokümantasyonu
    • Deployment checklist
  3. İyileştirmeler:

    • Rate limiting test et
    • Email template'lerini test et (MailPit ile)
    • Social auth provider'ları test et
    • Error mesajlarını frontend-friendly hale getir
    • Logging ekle (özellikle auth failures için)
  4. Güvenlik:

    • HTTPS için production settings
    • CSRF token stratejisi netleştir
    • JWT secret key'i environment variable'a taşı
    • Rate limiting değerlerini production için ayarla
  5. Opsiyonel Özellikler:

    • Email değiştirme flow'u
    • 2FA (Two-Factor Authentication)
    • Remember me functionality
    • Account deletion
    • Social account linking (birden fazla provider)

🐛 Bilinen Sorunlar:

  • Yok (şu an için)

📚 Referanslar: