Skip to content

Commit

Permalink
templates made for email for reset pswd and confirmation email
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifer1708 committed Feb 16, 2022
1 parent dbb21b4 commit 5d46fa8
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 39 deletions.
59 changes: 28 additions & 31 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from django.contrib import messages
from django.contrib.auth import login
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.shortcuts import render
from django.urls import reverse_lazy
from django.contrib.auth.views import PasswordResetView
from django.contrib.messages.views import SuccessMessageMixin
from django.core.mail.message import EmailMultiAlternatives
from django.shortcuts import redirect, render
from django.utils.encoding import force_str, force_bytes
# from django.urls import reverse
from django.contrib.sites.shortcuts import get_current_site
from .forms import SignUpForm
from .tokens import account_activation_token
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.http import HttpResponse
from django.template.loader import get_template
from django.http import HttpResponse, request
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from questions.lib.actions import show_leaderboard
# Create your views here.
Expand All @@ -36,41 +41,30 @@ def register(request):
# raw_password = form.cleaned_data.get('password1')
current_site = get_current_site(request)
mail_subject = 'Activate your account.'
message = render_to_string('email_template.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
})

to_email = form.cleaned_data.get('email')
send_mail(mail_subject, message, 'abhedya.iste@gmail.com', [to_email])
return HttpResponse('Please confirm your email address to complete the registration')
# else:
# form = SignUpForm()
# return render(request, 'register.html', {'form' : form})
# user = authenticate(username=user.username, password=raw_password)
# login(request, user)


# return redirect(reverse('hunt'))
# else:
# context = {
# 'form' : form,
# }
# return render(request,'register.html', context)
username = form.cleaned_data.get('username')
email = form.cleaned_data.get('email')
htmly = get_template('email_template.html')
cunt={
'username': username,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
}
from_email, to = 'abhedya.iste@gmail.com', email
html_content=htmly.render(cunt)
msg=EmailMultiAlternatives(mail_subject, html_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
messages.success(request, f'we have sent a confirmation email.' )
return redirect('home')

# Else return an empty form
form = SignUpForm()
context = {
'form' : form,
}

return render(request,'register.html', context)

# return render(request, 'user/login.html', {'form': form})


def activate(request, uidb64, token):
User = get_user_model()
try:
Expand All @@ -81,7 +75,8 @@ def activate(request, uidb64, token):
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
user.save()
return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
messages.success(request, f'Your email has been verified. You can login now' )
return redirect('rules')
else:
return HttpResponse('Activation link is invalid!')

Expand All @@ -107,3 +102,5 @@ def home(request):

def rules(request):
return render(request, 'rules.html')


4 changes: 2 additions & 2 deletions cryptic/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
path('logout/', auth_views.LogoutView.as_view(template_name = 'home.html'),name='logout'),
path('',home, name='home'),
path('rules/',rules, name="rules"),
path("password-reset/", auth_views.PasswordResetView.as_view(template_name='user/password_reset.html'), name="password_reset"),
path("password-reset/", auth_views.PasswordResetView.as_view(template_name='user/password_reset.html', html_email_template_name = 'user/password_reset_email.html' ), name="password_reset"),
path("password-reset/done/", auth_views.PasswordResetDoneView.as_view(template_name='user/password_reset_done.html'), name="password_reset_done"),
path("password-reset-confirm/<uidb64>/<token>/", auth_views.PasswordResetConfirmView.as_view(template_name='user/password_reset_confirm.html'), name="password_reset_confirm"),
path("password-reset-complete/", auth_views.PasswordResetCompleteView.as_view(template_name='user/password_reset_complete.html'), name="password_reset_complete"),
path('emailVerification/<uidb64>/<token>',activate, name='emailActivate'),
path('activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/',activate, name='activate'),
path('activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/',activate, name='activate'),
]


Expand Down
Binary file modified db.sqlite3
Binary file not shown.
197 changes: 191 additions & 6 deletions templates/email_template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,191 @@
{% autoescape off %}
Hi ,
Please click on the link to confirm your registration,
<!-- http://{{ domain }}{% url 'activate' uidb64=uid token=token %} -->
http://{{ domain }}/emailVerification/{{ uid }}/{{ token }}
{% endautoescape %}
<!DOCTYPE html>
<html>

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<style type="text/css">
@media screen {
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: local('Lato Regular'), local('Lato-Regular'), url(https://fonts.gstatic.com/s/lato/v11/qIIYRU-oROkIk8vfvxw6QvesZW2xOQ-xsNqO47m55DA.woff) format('woff');
}

@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: local('Lato Bold'), local('Lato-Bold'), url(https://fonts.gstatic.com/s/lato/v11/qdgUG4U09HnJwhYI-uK18wLUuEpTyoUstqEm5AMlJo4.woff) format('woff');
}

@font-face {
font-family: 'Lato';
font-style: italic;
font-weight: 400;
src: local('Lato Italic'), local('Lato-Italic'), url(https://fonts.gstatic.com/s/lato/v11/RYyZNoeFgb0l7W3Vu1aSWOvvDin1pK8aKteLpeZ5c0A.woff) format('woff');
}

@font-face {
font-family: 'Lato';
font-style: italic;
font-weight: 700;
src: local('Lato Bold Italic'), local('Lato-BoldItalic'), url(https://fonts.gstatic.com/s/lato/v11/HkF_qI1x_noxlxhrhMQYELO3LdcAZYWl9Si6vvxL-qU.woff) format('woff');
}
}

/* CLIENT-SPECIFIC STYLES */
body,
table,
td,
a {
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}

table,
td {
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
}

img {
-ms-interpolation-mode: bicubic;
}

/* RESET STYLES */
img {
border: 0;
height: auto;
line-height: 100%;
outline: none;
text-decoration: none;
}

table {
border-collapse: collapse !important;
}

body {
height: 100% !important;
margin: 0 !important;
padding: 0 !important;
width: 100% !important;
}

/* iOS BLUE LINKS */
a[x-apple-data-detectors] {
color: inherit !important;
text-decoration: none !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}

/* MOBILE STYLES */
@media screen and (max-width:600px) {
h1 {
font-size: 32px !important;
line-height: 32px !important;
}
}

/* ANDROID CENTER FIX */
div[style*="margin: 16px 0;"] {
margin: 0 !important;
}
</style>
</head>

<body style="background-color: #f4f4f4; margin: 0 !important; padding: 0 !important;">
<!-- HIDDEN PREHEADER TEXT -->
<div style="display: none; font-size: 1px; color: #fefefe; line-height: 1px;
font-family: 'Lato', Helvetica, Arial, sans-serif; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;">
We're thrilled to have you here! Get ready to dive into your new account. </div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<!-- LOGO -->
<tr>
<td bgcolor="#039628" align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
<tr>
<td align="center" valign="top" style="padding: 40px 10px 40px 10px;"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#039628" align="center" style="padding: 0px 10px 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
<tr>
<td bgcolor="#ffffff" align="center" valign="top"
style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #111111; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; letter-spacing: 4px; line-height: 48px;">
<h1 style="font-size: 48px; font-weight: 400; margin: 2;">Welcome!</h1> <img
src=" https://img.icons8.com/clouds/100/000000/handshake.png" width="125" height="120"
style="display: block; border: 0px;" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#f4f4f4" align="center" style="padding: 0px 10px 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
<tr>
<td bgcolor="#ffffff" align="left"
style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;">
<p style="margin: 0;">We're excited to have you get started. First, you need to confirm your account. Just
press the button below.</p>
</td>
</tr>
<tr>
<td bgcolor="#ffffff" align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" style="border-radius: 3px;" bgcolor="#039768"><a
href="http://{{ domain }}/emailVerification/{{ uid }}/{{ token }}" target="_blank"
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #039768; display: inline-block;">Confirm
Account</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr> <!-- COPY -->

<tr>
<td bgcolor="#ffffff" align="left"
style="padding: 0px 30px 40px 30px; border-radius: 0px 0px 4px 4px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;">
<p style="margin: 0;">Regards,<br>TEAM ISTE</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#f4f4f4" align="center" style="padding: 30px 10px 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
<tr>
<td bgcolor="#FFECD1" align="center"
style="padding: 30px 30px 30px 30px; border-radius: 4px 4px 4px 4px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;">
<h2 style="font-size: 20px; font-weight: 400; color: #111111; margin: 0;">Need more help?</h2>
<p style="margin: 0;"><a href="https://www.istenith.com" target="_blank"
style="color: #039768;">We&rsquo;re here to help you
out</a></p>
</td>
</tr>
</table>
</td>
</tr>

</table>
</body>

</html>
Empty file added templates/email_verified.html
Empty file.
Loading

0 comments on commit 5d46fa8

Please sign in to comment.