summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2025-07-10 22:14:32 +0530
committerSunil Shetye2025-07-10 22:14:32 +0530
commit745d3ba27d1aab1654f4963cc664d229bc56548b (patch)
tree8c3ddf47e256b7746f432b09b3d1a8b83a619671
parent21f01a3363a532299da6e8ba54d38bcafdc9953c (diff)
downloadCommon-Interface-Project-745d3ba27d1aab1654f4963cc664d229bc56548b.tar.gz
Common-Interface-Project-745d3ba27d1aab1654f4963cc664d229bc56548b.tar.bz2
Common-Interface-Project-745d3ba27d1aab1654f4963cc664d229bc56548b.zip
get protocol and domain from POST_ACTIVATE_REDIRECT_URL
-rw-r--r--blocks/authAPI/emails.py16
-rw-r--r--blocks/blocks/settings.py9
2 files changed, 25 insertions, 0 deletions
diff --git a/blocks/authAPI/emails.py b/blocks/authAPI/emails.py
new file mode 100644
index 00000000..2f112c74
--- /dev/null
+++ b/blocks/authAPI/emails.py
@@ -0,0 +1,16 @@
+from djoser import email
+from django.conf import settings
+
+
+class CustomActivationEmail(email.ActivationEmail):
+ def get_context_data(self):
+ context = super().get_context_data()
+ context['protocol'] = settings.DEFAULT_PROTOCOL
+ return context
+
+
+class CustomPasswordResetEmail(email.PasswordResetEmail):
+ def get_context_data(self):
+ context = super().get_context_data()
+ context['protocol'] = settings.DEFAULT_PROTOCOL
+ return context
diff --git a/blocks/blocks/settings.py b/blocks/blocks/settings.py
index aba1009f..e62c1fda 100644
--- a/blocks/blocks/settings.py
+++ b/blocks/blocks/settings.py
@@ -13,6 +13,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
import os
from pathlib import Path
from dotenv import load_dotenv
+from urllib.parse import urlparse
# Loading the .env file
load_dotenv()
@@ -155,6 +156,10 @@ GITHUB_OAUTH_REDIRECT_URI = os.environ.get('GITHUB_OAUTH_REDIRECT_URI',
'http://localhost/api/auth/github-callback')
POST_ACTIVATE_REDIRECT_URL = os.environ.get('POST_ACTIVATE_REDIRECT_URL',
'http://localhost/')
+parsed_url = urlparse(POST_ACTIVATE_REDIRECT_URL)
+DEFAULT_PROTOCOL = parsed_url.scheme or 'http'
+DOMAIN = parsed_url.netloc or 'localhost'
+SITE_NAME = os.environ.get('EMAIL_SITE_NAME', 'Xcos')
DJOSER = {
'LOGIN_FIELD': 'email',
@@ -178,6 +183,10 @@ DJOSER = {
'user_delete': 'djoser.serializers.UserDeleteSerializer',
'token_create': 'authAPI.serializers.TokenCreateSerializer',
},
+ 'EMAIL': {
+ 'activation': 'authAPI.emails.CustomActivationEmail',
+ 'password_reset': 'authAPI.emails.CustomPasswordResetEmail',
+ }
}
REST_FRAMEWORK = {