mirror of
https://github.com/Rushilwiz/launchx.git
synced 2025-04-04 12:10:17 -04:00
feat: added email confirmation
This commit is contained in:
parent
0fd8396b36
commit
04f8f9ad2c
|
@ -154,3 +154,15 @@ MEDIA_URL = '/media/'
|
|||
|
||||
LOGIN_REDIRECT_URL = 'blog-home'
|
||||
LOGIN_URL = 'login'
|
||||
|
||||
|
||||
# Email
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
|
||||
EMAIL_HOST = 'smtp.gmail.com'
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_HOST_USER = secrets.EMAIL_USER
|
||||
EMAIL_HOST_PASSWORD = secrets.EMAIL_PASSWORD
|
||||
|
||||
|
|
|
@ -6,10 +6,12 @@ from .models import Competitor, Team
|
|||
class CompetitorForm(forms.ModelForm):
|
||||
name = forms.CharField(label='Full Name', widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'John Doe'}))
|
||||
email = forms.EmailField(label='Email', widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'example@email.com'}))
|
||||
|
||||
school = forms.CharField(label='School', widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'TJHSST'}))
|
||||
county = forms.CharField(label='County', widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Fairfax'}))
|
||||
|
||||
class Meta:
|
||||
model = Competitor
|
||||
fields = ['name', 'email']
|
||||
fields = ['name', 'email', 'school', 'county']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CompetitorForm, self).__init__(*args, **kwargs)
|
||||
|
|
23
innovate/migrations/0003_auto_20210211_0122.py
Normal file
23
innovate/migrations/0003_auto_20210211_0122.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.1.6 on 2021-02-11 01:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('innovate', '0002_auto_20210208_1549'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='competitor',
|
||||
name='county',
|
||||
field=models.CharField(blank=True, default='', max_length=20),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='competitor',
|
||||
name='school',
|
||||
field=models.CharField(blank=True, default='', max_length=20),
|
||||
),
|
||||
]
|
|
@ -22,7 +22,9 @@ class Team(models.Model):
|
|||
|
||||
class Competitor(models.Model):
|
||||
name = models.CharField(max_length=20, blank=True, default='')
|
||||
email = models.EmailField(max_length = 254)
|
||||
email = models.EmailField(max_length=254)
|
||||
school = models.CharField(max_length=20, blank=True, default='')
|
||||
county = models.CharField(max_length=20, blank=True, default='')
|
||||
is_leader = models.BooleanField(default=False)
|
||||
|
||||
team = models.ForeignKey(Team, related_name="competitors", on_delete=models.CASCADE)
|
||||
|
|
18
innovate/templates/innovate/email_template.html
Normal file
18
innovate/templates/innovate/email_template.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<h1>Hey team, {{ team.name }}!</h1>
|
||||
|
||||
<p>Thanks for registering for <strong>InnovateTJ</strong>! This is a confirmation email for your registration. Your team is number {{ team.number }}. This number will be used for pitching and grading purposes. If you have any questions prior to the event, please email us <a href="mailto:tjhsstlaunchx@gmail.com">here</a>.</p>
|
||||
<br>
|
||||
Your team includes:
|
||||
<br>
|
||||
{% for member in members %}
|
||||
<p>Team Member {{ forloop.counter }}: {{ member.name }}</p>
|
||||
<p><i>From {{ member.school }} @ {{ member.school }}</i></p>
|
||||
<br>
|
||||
{% endfor %}
|
||||
<p>We'll be seeing you on February 20th, 2021 from 9AM to 5AM, and more information will be sent out as the event nears! But until then, keep innovating.</p>
|
||||
<br>
|
||||
<p>
|
||||
Best,<br>
|
||||
InnovateTJ Team<br>
|
||||
tjhsstlaunchx@gmail.com
|
||||
</p>
|
|
@ -41,6 +41,16 @@
|
|||
{{ form.email.label_tag }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="form-floating col-5">
|
||||
{{ form.school }}
|
||||
{{ form.school.label_tag }}
|
||||
</div>
|
||||
<div class="form-floating col-5">
|
||||
{{ form.county }}
|
||||
{{ form.county.label_tag }}
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
{% endfor %}
|
||||
{% for hidden in team_form.hidden_fields %}
|
||||
|
|
|
@ -3,29 +3,70 @@ from django.shortcuts import render, redirect
|
|||
from .forms import CompetitorFormset, CompetitorForm, TeamForm
|
||||
from .models import Competitor
|
||||
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.html import strip_tags
|
||||
from config.settings import EMAIL_HOST_USER
|
||||
from django.core.mail import EmailMultiAlternatives, send_mail
|
||||
|
||||
# Create your views here.
|
||||
def home(request):
|
||||
return render(request, 'innovate/index.html')
|
||||
|
||||
def signup(request):
|
||||
formset = CompetitorFormset()
|
||||
team_form = TeamForm()
|
||||
|
||||
if request.method == 'POST':
|
||||
formset = CompetitorFormset(request.POST)
|
||||
team_form = TeamForm(request.POST, request.FILES)
|
||||
if formset.is_valid() and team_form.is_valid():
|
||||
team = team_form.save()
|
||||
is_leader = True
|
||||
members = []
|
||||
for form in formset:
|
||||
name = form.cleaned_data.get('name')
|
||||
email = form.cleaned_data.get('email')
|
||||
if name and email:
|
||||
m = Competitor(name=name, email=email, is_leader=is_leader, team=team)
|
||||
school = form.cleaned_data.get('school')
|
||||
county = form.cleaned_data.get('school')
|
||||
if name and email and school and county:
|
||||
m = Competitor(name=name, email=email, school=school, county=county, is_leader=is_leader, team=team)
|
||||
m.save()
|
||||
is_leader = False
|
||||
members.append(m)
|
||||
send_confirmation(request, team,members)
|
||||
return redirect('landing')
|
||||
|
||||
formset = CompetitorFormset()
|
||||
team_form = TeamForm()
|
||||
return render(request, 'innovate/signup.html', {'formset': formset, 'team_form': team_form})
|
||||
|
||||
|
||||
def send_confirmation(request, team, members):
|
||||
#subject = "🥳 InnovateTJ Signup Confirmation 🥳"
|
||||
subject = "OK NO THIS ONE IS THE LAST EMAIL"
|
||||
#recepients = []
|
||||
#for member in members:
|
||||
# recepients.append(member.email)
|
||||
recepients = ['rushilwiz@gmail.com', 'ssuganuma04@gmail.com']
|
||||
|
||||
context = {
|
||||
'team': team,
|
||||
'members': members
|
||||
}
|
||||
|
||||
html_message = render_to_string('innovate/email_template.html', context=context)
|
||||
plain_message = strip_tags(html_message)
|
||||
sender = [EMAIL_HOST_USER]
|
||||
email = EmailMultiAlternatives(
|
||||
subject,
|
||||
plain_message,
|
||||
EMAIL_HOST_USER,
|
||||
recepients,
|
||||
reply_to=sender
|
||||
)
|
||||
print(request.POST.getlist('rep'))
|
||||
email.attach_alternative(html_message, "text/html")
|
||||
print("### EMAIL SENT ###")
|
||||
print (recepients)
|
||||
email.send(fail_silently=False)
|
||||
|
||||
def confirm(request):
|
||||
return render(request, 'innovate/confirm.html')
|
|
@ -8,5 +8,7 @@
|
|||
SECRET_KEYS = [
|
||||
# start with your Django secret key like this:
|
||||
"SECRET_KEY",
|
||||
"DEBUG"
|
||||
"DEBUG",
|
||||
"EMAIL_USER",
|
||||
"EMAIL_PASSWORD"
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user