Skip to content

Commit

Permalink
Merge pull request #164 from avantifellows/feature/trigger-waitlist-e…
Browse files Browse the repository at this point in the history
…mail

Trigger email on user approved
  • Loading branch information
dalmia authored May 14, 2021
2 parents f638993 + 012fb72 commit b1aee28
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ AUTH0_TOKEN_URL=
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=
AUTH0_AUDIENCE=

# email settings
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_USE_TLS=True
EMAIL_PORT=587
DEFAULT_FROM_EMAIL=Plio <no-reply@plio.in>
EMAIL_HOST_USER= # sender's email-id
# password associated with above email-id
# for accounts with 2-factor authentication, you have to create a application-specific
# passwords. More on that here:
# https://dev.to/abderrahmanemustapha/how-to-send-email-with-django-and-gmail-in-production-the-right-way-24ab
EMAIL_HOST_PASSWORD=
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -e

# collect static files
python manage.py collectstatic --no-input

# run migrations
python manage.py migrate

Expand Down
10 changes: 10 additions & 0 deletions plio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,17 @@
}
}

# authentication
AUTH0_TOKEN_URL = os.environ.get("AUTH0_TOKEN_URL")
AUTH0_CLIENT_ID = os.environ.get("AUTH0_CLIENT_ID")
AUTH0_CLIENT_SECRET = os.environ.get("AUTH0_CLIENT_SECRET")
AUTH0_AUDIENCE = os.environ.get("AUTH0_AUDIENCE")

# email
EMAIL_BACKEND = os.environ.get("EMAIL_BACKEND")
EMAIL_HOST = os.environ.get("EMAIL_HOST")
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS")
EMAIL_PORT = os.environ.get("EMAIL_PORT")
DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL")
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
140 changes: 140 additions & 0 deletions plio/templates/waitlist-approve-email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html>
<head>
<style>
.text-white {
--tw-text-opacity: 1;
color: rgba(255, 255, 255, var(--tw-text-opacity));
}
.text-lg {
font-size: 1.25rem;
line-height: 1.75rem;
}
</style>
</head>
<body>
<div>
<div style="background-color:#eaedec">
<div style="margin:0px auto;max-width:680px">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;padding-bottom:0px;padding-top:0px;text-align:center">
<div class="m_1481667341338239460mj-column-px-680" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top" width="100%">
<tbody>
<tr>
<td align="center" style="font-size:0px;padding:0px;word-break:break-word">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px">
<tbody>
<tr>
<td style="width:680px">
<img alt="" height="auto" src="https://raw.githubusercontent.com/avantifellows/plio-frontend/master/src/assets/images/Banner.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;font-size:13px" width="680" class="CToWUd a6T" tabindex="0">
<div class="a6S" dir="ltr" style="opacity: 0.01; left: 632px; top: 174px;">
<div id=":11n" class="T-I J-J5-Ji aQv T-I-ax7 L3 a5q" role="button" tabindex="0" aria-label="Download attachment " data-tooltip-class="a1V" data-tooltip="Download">
<div class="akn">
<div class="aSK J-J5-Ji aYr"></div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="background:white;background-color:white;margin:0px auto;max-width:680px">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:white;background-color:white;width:100%">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;padding-bottom:0px;padding-top:0px;text-align:center">
<div style="margin:0px auto;max-width:680px">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center">
<div class="m_1481667341338239460mj-column-px-680" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top" width="100%">
<tbody>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word">
<div style="font-family:Encode Sans,Helvetica,Arial,-apple-system,sans-serif;font-size:16px;font-weight:400;line-height:24px;text-align:left;color:#5e5e5e">Hooray 🎉 You’re off the waitlist - welcome to Plio :)<br><br>With Plio, you can unlock the true potential of videos by making them interactive and understanding how your viewers engage with them.<br><br>Start pliofying the world by making your videos interactive today.</div>
</td>
</tr>
<tr>
<td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;line-height:100%">
<tbody>
<tr>
<td align="center" bgcolor="#F78000" role="presentation" style="border:none;border-radius:4px;background:#F78000" valign="middle"><a href="https://app.plio.in/" style="display:inline-block;background:#F78000;color:#ffffff;font-family:Encode Sans,Helvetica,Arial,-apple-system,sans-serif;font-size:18px;font-weight:300;line-height:30px;margin:0;text-decoration:none;text-transform:none;padding:12px 50px;border-radius:4px" target="_blank">Create a Plio</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word">
<div style="font-family:Encode Sans,Helvetica,Arial,-apple-system,sans-serif;font-size:16px;font-weight:400;line-height:24px;text-align:left;color:#5e5e5e"><br>We sincerely hope that you'll enjoy Plio and we are eagerly waiting to hear from you about your experience.</div>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word">
<div style="font-family:Encode Sans,Helvetica,Arial,-apple-system,sans-serif;font-size:16px;font-weight:400;line-height:24px;text-align:left;color:#5e5e5e">Cheers,<br>Plioneers</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin:0px auto;max-width:680px">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center">
<div class="m_1481667341338239460mj-column-px-680" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top" width="100%">
<tbody>
<tr>
<td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word">
<div style="font-family:Encode Sans,Helvetica,Arial,-apple-system,sans-serif;font-size:14px;font-weight:400;line-height:24px;text-align:center;color:#5e5e5e"><a href="https://plio.in" style="text-decoration:none" target="_blank">www.<span class="il">plio</span>.in</a><br>Bengaluru, India</div>
</td>
</tr>
<tr>
<td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px">
<tbody>
<tr>
<td style="width:32px"><a href="https://twitter.com/learn_from_plio" target="_blank"><img height="auto" src="https://ci4.googleusercontent.com/proxy/-k49hjOcV0EjhZcA3zTYYPJndgWLPcv4IZvOOy6LMm3uS0Dh8KuMf2H6zk87QVj2S2awMaxo1BZwWNgoDCQpHuluX-Rl_nnP4mmu6DAyh0GXGWDwKVgxkg=s0-d-e1-ft#https://centered-images.s3-us-west-1.amazonaws.com/emails/twitter.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;font-size:13px" width="32" class="CToWUd"></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion plio/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"""
from django.contrib import admin
from django.urls import path, include
from rest_framework import routers, permissions
from django.conf.urls import url
from rest_framework import routers, permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from tags.views import TagViewSet
Expand Down
44 changes: 31 additions & 13 deletions users/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
from rest_framework.decorators import api_view, permission_classes, action
from rest_framework.permissions import AllowAny
from rest_framework import viewsets, status
from rest_framework.response import Response

import datetime
import string
import random
from oauth2_provider.models import AccessToken, Application, RefreshToken

from asgiref.sync import async_to_sync
from django.contrib.auth import login
from django.dispatch import receiver
from django.db.models.signals import post_save, pre_save, post_delete
from django.core.mail import send_mail
from django.template.loader import render_to_string
from channels.layers import get_channel_layer

from plio.settings import (
API_APPLICATION_NAME,
Expand All @@ -9,25 +24,13 @@
AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET,
AUTH0_AUDIENCE,
DEFAULT_FROM_EMAIL,
)

from rest_framework import viewsets, status
from rest_framework.response import Response
from users.models import User, OneTimePassword, OrganizationUser
from users.serializers import UserSerializer, OtpSerializer, OrganizationUserSerializer

import datetime
import string
import random
from django.contrib.auth import login
from oauth2_provider.models import AccessToken, Application, RefreshToken
from .services import SnsService

from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.dispatch import receiver
from django.db.models.signals import post_save, pre_save, post_delete

import requests


Expand Down Expand Up @@ -197,6 +200,21 @@ def update_user(sender, instance: User, **kwargs):
user_group_name, {"type": "send_user", "data": user_data}
)

# send an email if the user has been approved
if instance.email and instance.status == "approved":
subject = "Congrats - You're off the Plio waitlist! 🎉"
recipient_list = [
instance.email,
]
html_message = render_to_string("waitlist-approve-email.html")
send_mail(
subject=subject,
message=None,
from_email=DEFAULT_FROM_EMAIL,
recipient_list=recipient_list,
html_message=html_message,
)


@receiver(post_save, sender=OrganizationUser)
@receiver(post_delete, sender=OrganizationUser)
Expand Down

0 comments on commit b1aee28

Please sign in to comment.