Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ staticfiles
python-env
.DS_Store
data/db
.vscode
Empty file added account_settings/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions account_settings/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions account_settings/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class EmailsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'contact_emails'
Empty file.
3 changes: 3 additions & 0 deletions account_settings/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
6 changes: 6 additions & 0 deletions account_settings/templates/emails/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<h1>Message</h1>
</body>
</html>
33 changes: 33 additions & 0 deletions account_settings/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json

from django.core import mail
from django.test import Client, TestCase
from rest_framework import status


class ContactEmailsTest(TestCase):
def test_post_index_request_success(self):
client = Client()
response = client.post(
'/api/v1/contact_emails',
json.dumps({
'email': '[email protected]',
'message': 'That\'s your message body',
'name': 'Example Username',
'reference': 'Example reference text',
'topicType': 'Example topic type',
}),
content_type='application/json',
)
data = response.json()
email_body = mail.outbox[0].body
email_subject = mail.outbox[0].subject
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual('Contact Form Submission', email_subject)
self.assertIn('email: [email protected]', email_body)
self.assertIn('message: That\'s your message body', email_body)
self.assertIn('reference: Example reference text', email_body)
self.assertIn('topic: Example topic type', email_body)


6 changes: 6 additions & 0 deletions account_settings/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('delete_user_account', views.delete_user, name='email'),
]
30 changes: 30 additions & 0 deletions account_settings/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import json
from django.contrib.auth import get_user_model
from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponse
from django.core.mail import send_mail
from rest_framework.decorators import api_view
from rest_framework import status
from rest_framework.response import Response


@api_view(['DELETE'])

def delete_user(request, email):
"""
API endpoint for deleting user account
"""
# User = get_user_model()
user = User.objects.get(email=email)
if request.method == 'DELETE':
user.delete()
return JsonResponse({'message': 'User deleted successfully.'}, status=204)
else:
return HttpResponse(status=405)

# return Response({'status': 'Success'}, status=status.HTTP_201_CREATED)
#does this need to be organized as a class? class UserViewSet(viewsets.ModelViewSet):