Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion back-end/account/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from djoser.conf import settings as djoser_settings
from urllib.parse import urlparse

Expand All @@ -21,7 +22,16 @@ def build_frontend_url(path: str):

prefix = "/".join(parts[:-2])

domain = djoser_settings.DOMAIN
domain = getattr(djoser_settings, "DOMAIN", None)
if not domain:
frontend_url = getattr(settings, "FRONTEND_URL", "")
parsed_frontend = urlparse(frontend_url)
domain = parsed_frontend.netloc or frontend_url

if not domain:
raise ValueError(
"Unable to construct email link: set DJOSER.DOMAIN or PUBLIC_APP_URL/FRONTEND_URL."
)

return f"https://{domain}/{prefix}/{uid}/{token}"

Expand Down
20 changes: 18 additions & 2 deletions back-end/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from pathlib import Path
import os
from urllib.parse import urlparse
import dj_database_url
from dotenv import load_dotenv
import cloudinary
Expand Down Expand Up @@ -50,6 +51,7 @@
"djoser",
"corsheaders",
"drf_spectacular",
"anymail",
"cloudinary_storage",
"cloudinary",
]
Expand Down Expand Up @@ -217,6 +219,8 @@
"USER_CREATE_PASSWORD_RETYPE": True,
"ACTIVATION_URL": "verify-email/{uid}/{token}",
"PASSWORD_RESET_CONFIRM_URL": "reset-password/{uid}/{token}",
"DOMAIN": urlparse(os.environ.get("PUBLIC_APP_URL", "http://localhost:5173")).netloc
or os.environ.get("PUBLIC_APP_URL", "localhost:5173"),
"SERIALIZERS": {
"user_create": "account.serializers.UserCreateSerializer",
"user": "account.serializers.UserSerializer",
Expand All @@ -225,6 +229,10 @@
"VIEWS": {
"user_create": "account.views.CustomUserViewSet"
},
"EMAIL": {
"activation": "account.email.CustomActivationEmail",
"password_reset": "account.email.CustomPasswordResetEmail",
},
}

# ─── CORS ───────────────────────────────────────────────────
Expand Down Expand Up @@ -254,13 +262,21 @@
GOOGLE_CLIENT_SECRET = os.environ.get("GOOGLE_CLIENT_SECRET", "").strip()

# ─── Email ──────────────────────────────────────────────────
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
SENDGRID_API_KEY = os.environ.get("SENDGRID_API_KEY", "")
ANYMAIL = {
"SENDGRID_API_KEY": SENDGRID_API_KEY,
}
EMAIL_BACKEND = (
"anymail.backends.sendgrid.EmailBackend"
if SENDGRID_API_KEY
else "django.core.mail.backends.smtp.EmailBackend"
)
EMAIL_HOST = os.environ.get("EMAIL_HOST", "smtp.gmail.com")
EMAIL_PORT = int(os.environ.get("EMAIL_PORT", 587))
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS", "True") == "True"
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", "")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", "")
DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL", "noreply@onlinetherapy.com")
DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_FROM", os.environ.get("DEFAULT_FROM_EMAIL", "noreply@onlinetherapy.com"))

# Frontend URL (for email links)
FRONTEND_URL = os.environ.get("PUBLIC_APP_URL", "http://localhost:5173")
Expand Down
9 changes: 7 additions & 2 deletions back-end/core/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""Development Settings"""
from .base import * # noqa: F401, F403
import os

DEBUG = True

# Show emails in console during development
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Use console backend when SendGrid is not configured in development.
EMAIL_BACKEND = (
"anymail.backends.sendgrid.EmailBackend"
if os.environ.get("SENDGRID_API_KEY")
else "django.core.mail.backends.console.EmailBackend"
)

# Django Debug Toolbar (optional but useful)
INSTALLED_APPS += ["django_extensions"] # noqa: F405
Expand Down
1 change: 1 addition & 0 deletions back-end/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = [
"groq>=0.5.0",
"cloudinary>=1.44.2",
"django-cloudinary-storage>=0.3.0",
"django-anymail[sendgrid]>=9.4.0",
]

[project.optional-dependencies]
Expand Down
22 changes: 22 additions & 0 deletions back-end/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.