✨ Feat: [#84] 랜딩페이지 이메일 수집 및 정식런칭 이메일 발송 기능 구현
This commit is contained in:
@@ -66,7 +66,7 @@ INSTALLED_APPS = [
|
||||
'codes',
|
||||
'notifications',
|
||||
'nocodetools',
|
||||
# 'homes',
|
||||
'homes',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -270,6 +270,14 @@ GOOGLE_CLIENT_ID = env('GOOGLE_CLIENT_ID')
|
||||
GITHUB_CLIENT_ID = env('GITHUB_CLIENT_ID')
|
||||
GITHUB_CLIENT_SECRET = env('GITHUB_CLIENT_SECRET')
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = env('EMAIL_HOST')
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_PORT = env('EMAIL_PORT')
|
||||
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
|
||||
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
|
||||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
||||
|
||||
##CORS
|
||||
# CSRF_TRUSTED_ORIGINS = []
|
||||
# CORS_ALLOWED_ORIGINS = ["http://localhost:3000", "https://{프론트주소}.vercel.app/"]
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.db import models
|
||||
|
||||
from common.models.baseModels import BaseModel
|
||||
|
||||
class PreOrderedEmail(BaseModel):
|
||||
email = models.EmailField()
|
||||
@@ -1 +1,10 @@
|
||||
# 포폴, 플젝 주간 랭킹, 광고 등
|
||||
from .models import *
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class PreOrderedEmailSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = PreOrderedEmail
|
||||
fields = ['email']
|
||||
@@ -1,9 +1,15 @@
|
||||
from django.urls import include, path
|
||||
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from .views import *
|
||||
|
||||
preorder_router = DefaultRouter(trailing_slash=True)
|
||||
preorder_router.register(r"email", PreOrderedAPIViewSet, basename="preorder")
|
||||
|
||||
app_name = 'homes'
|
||||
|
||||
urlpatterns = [
|
||||
path('search/', SearchAPIView.as_view()),
|
||||
path("preorder/", include(preorder_router.urls)),
|
||||
]
|
||||
@@ -1,13 +1,18 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status, mixins, viewsets
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated, IsAdminUser
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
from django.core.mail import EmailMessage, get_connection
|
||||
|
||||
from .models import *
|
||||
from .serializers import *
|
||||
from .services import *
|
||||
|
||||
|
||||
from projects.models import Project
|
||||
from projects.serializers import ProjectListViewSerializer
|
||||
|
||||
@@ -51,3 +56,36 @@ class SearchAPIView(APIView):
|
||||
"page": page,
|
||||
"page_size": page_size
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class PreOrderedAPIViewSet(viewsets.ViewSet):
|
||||
|
||||
@transaction.atomic
|
||||
@action(detail=False, methods=["post"], url_path="register", permission_classes=[AllowAny])
|
||||
def register(self, request):
|
||||
serializer = PreOrderedEmailSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response({"registered": True}, status=status.HTTP_200_OK)
|
||||
return Response({"registered": False}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@transaction.atomic
|
||||
@action(detail=False, methods=["post"], url_path="send", permission_classes=[IsAdminUser])
|
||||
def send(self, request):
|
||||
try:
|
||||
title = request.data["title"]
|
||||
content = request.data["content"]
|
||||
conn = get_connection()
|
||||
emails = []
|
||||
email_list = PreOrderedEmail.objects.all()
|
||||
for i, email_obj in enumerate(email_list):
|
||||
if i >= 0 and i % 20 == 0:
|
||||
conn.send_messages(emails)
|
||||
conn.close()
|
||||
conn = get_connection()
|
||||
emails = []
|
||||
emails.append(EmailMessage(subject=title, body=content, to=[email_obj.email], connection=conn))
|
||||
conn.send_messages(emails)
|
||||
return Response({"success": True}, status=status.HTTP_200_OK)
|
||||
except Exception as e:
|
||||
return Response({"success": False, "error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
Reference in New Issue
Block a user