From 2b53c3de6aa680335575daa23a3d13e142e0b979 Mon Sep 17 00:00:00 2001
From: Chris Li <c58li@uwaterloo.ca>
Date: Tue, 4 Apr 2023 22:40:33 -0400
Subject: [PATCH] Enable email sending function.

---
 core/signals.py                          | 10 +++++-----
 ece651_backend/settings.py               | 24 ++++++++++++++++++------
 ece651_backend/urls.py                   |  3 +--
 templates/email/user_reset_password.html | 14 ++++++++------
 templates/email/user_verification.html   | 21 ++++++++++++++-------
 5 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/core/signals.py b/core/signals.py
index fc3b6af..a2ad361 100644
--- a/core/signals.py
+++ b/core/signals.py
@@ -25,7 +25,7 @@ def send_activation_email(sender, instance, created, *args, **kwargs):
             'current_user': instance,
             'username': instance.username,
             'email': instance.email,
-            'domain': 'localhost:8000',
+            'domain': 'hamsterwhat.com',
             'token': AuthToken.objects.create(instance)[0].digest
         }
 
@@ -34,11 +34,11 @@ def send_activation_email(sender, instance, created, *args, **kwargs):
 
         msg = EmailMessage(
             # title:
-            "User Verification for {title}".format(title="Some website title"),
+            "User Verification for {title}".format(title="HamsterWhat"),
             # message:
             email_html_message,
             # from:
-            "noreply@somehost.local",
+            "hamsterwhat@gmail.com",
             # to:
             [instance.email]
         )
@@ -61,11 +61,11 @@ def password_reset_token_created(sender, instance, reset_password_token, *args,
 
     msg = EmailMessage(
         # title:
-        "Password Reset for {title}".format(title="Some website title"),
+        "Password Reset for {title}".format(title="HamsterWhat"),
         # message:
         email_html_message,
         # from:
-        "noreply@somehost.local",
+        "hamsterwhat@gmail.com",
         # to:
         [reset_password_token.user.email]
     )
diff --git a/ece651_backend/settings.py b/ece651_backend/settings.py
index 1c33262..a1f6ae7 100644
--- a/ece651_backend/settings.py
+++ b/ece651_backend/settings.py
@@ -54,8 +54,8 @@ REST_FRAMEWORK = {
 }
 
 REST_KNOX = {
-  'TOKEN_TTL': timedelta(days=7),
-  'AUTO_REFRESH': True,
+    'TOKEN_TTL': timedelta(days=7),
+    'AUTO_REFRESH': True,
 }
 
 MIDDLEWARE = [
@@ -130,13 +130,20 @@ TIME_ZONE = 'America/Toronto'
 
 USE_I18N = True
 
-USE_TZ = False
-
+USE_TZ = True
 
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/4.1/howto/static-files/
 
 STATIC_URL = 'static/'
+STATIC_ROOT = os.path.join(BASE_DIR, "static/")
+
+STATICFILES_DIRS = (
+    ("js", os.path.join(STATIC_ROOT, 'js')),
+    ("css", os.path.join(STATIC_ROOT, 'css')),
+    ("images", os.path.join(STATIC_ROOT, 'images')),
+    ("fonts", os.path.join(STATIC_ROOT, 'fonts')),
+)
 
 # Default primary key field type
 # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
@@ -144,8 +151,13 @@ STATIC_URL = 'static/'
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 
 # Email settings
-EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
+EMAIL_HOST = 'smtp.gmail.com'
+EMAIL_PORT = 587
+EMAIL_USE_TLS = True
+EMAIL_HOST_USER = 'hamsterwhat@gmail.com'
+EMAIL_HOST_PASSWORD = 'psqytbyafqujeiji'
 
 # Media Settings
 MEDIA_URL = 'media/'
-MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
+MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
diff --git a/ece651_backend/urls.py b/ece651_backend/urls.py
index bae7a3a..0a74aea 100644
--- a/ece651_backend/urls.py
+++ b/ece651_backend/urls.py
@@ -11,10 +11,9 @@ urlpatterns = router.urls
 
 urlpatterns += [
     path('', include('core.urls')),
-    # path('dj-rest-auth/', include('dj_rest_auth.urls')),
-    # path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),
     path('admin/', admin.site.urls),
     path('docs/', include_docs_urls(title='ECE651 Backend API Document', description='This API document includes all ednpoints that has been implemented.')),
 ]
 
+urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
 urlpatterns += static('media/', document_root=settings.MEDIA_ROOT)
diff --git a/templates/email/user_reset_password.html b/templates/email/user_reset_password.html
index d31ed7f..079133e 100644
--- a/templates/email/user_reset_password.html
+++ b/templates/email/user_reset_password.html
@@ -1,12 +1,14 @@
 {% autoescape off %}
-To initiate the password reset process for you {{ username }} for your BuyforFree Account,
-click the link below:
+Dear {{ username }},
+
+We received a request to reset the password for your account on HamsterWhat. If you did not make this request, please ignore this email.
+
+To reset your password, please click on the link below:
 
 {{reset_password_url}}
 
-If clicking the link above doesn't work, please copy and paste the URL in a new browser
-window instead.
+If you have any issues with the password reset process, please don't hesitate to contact our support team at hamsterwhat@gmail.com and we'll be happy to assist you.
 
-Sincerely,
-ECE651_DEMO
+Best regards,
+HamsterWhat Team
 {% endautoescape %}
\ No newline at end of file
diff --git a/templates/email/user_verification.html b/templates/email/user_verification.html
index 2ed1c06..5fb6f14 100644
--- a/templates/email/user_verification.html
+++ b/templates/email/user_verification.html
@@ -1,12 +1,19 @@
 {% autoescape off %}
-To initiate the password reset process for you {{ username }} for your Account,
-click the link below:
+Dear {{ username }},
 
-http://{{ domain }}{% url 'activate' token=token %}
+Thank you for signing up with HamsterWhat! We're excited to have you onboard.
 
-If clicking the link above doesn't work, please copy and paste the URL in a new browser
-window instead.
+Before you can start using your account, we need to verify your email address and activate your account. Please follow the instructions below to complete the activation process:
 
-Sincerely,
-ECE651_DEMO
+1. Click on the activation link below:
+https://{{ domain }}{% url 'activate' token=token %}
+
+2. Once you click the link, you will be taken to our website where you can receive a notice about whether you have successfully verified your account.
+
+If you have any issues with the activation process, please don't hesitate to contact our support team at hamsterwhat@gmail.com and we'll be happy to assist you.
+
+We look forward to having you as part of our community.
+
+Best regards,
+HamsterWhat Team
 {% endautoescape %}
\ No newline at end of file
-- 
GitLab