Skip to content

Commit

Permalink
Merge 8554f4e into cb62681
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan690 committed Jan 21, 2019
2 parents cb62681 + 8554f4e commit 1b77025
Show file tree
Hide file tree
Showing 12 changed files with 562 additions and 13 deletions.
35 changes: 34 additions & 1 deletion authors/apps/authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, *args, **kwargs):

# Ensure the username entered is unique and has a descriptive error message
# when a duplicate username is entered and an invalid username.

username = serializers.RegexField(
regex='^[A-Za-z\-\_]+\d*$',
min_length=3,
Expand All @@ -43,7 +44,8 @@ def __init__(self, *args, **kwargs):
email = serializers.EmailField(
validators=[UniqueValidator(
queryset=User.objects.all(),
message='Email already exists. Please enter another email or sign in'
message='Email already exists. '
'Please enter another email or sign in'
)],
error_messages={
'invalid': 'Please enter a valid email address'
Expand Down Expand Up @@ -199,3 +201,34 @@ def update(self, instance, validated_data):
instance.save()

return instance


class EmailCheckSerializer(serializers.Serializer):
email = serializers.EmailField()

def __init__(self, *args, **kwargs):
super(EmailCheckSerializer, self).__init__(*args, **kwargs)

# Override the default error_messages with a custom field error
for field in self.fields:
error_messages = self.fields[field].error_messages
error_messages['null'] = error_messages['blank'] \
= error_messages['required'] \
= 'Please supply your {}.'.format(field)


class PasswordResetSerializer(serializers.Serializer):
password = serializers.RegexField(
regex=r'^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\!\@#\$%\^&]).*',
max_length=128,
min_length=8,
write_only=True,
style={'input_type': 'password', 'placeholder': 'Password'},
error_messages={
'max_length': 'Password allows a maximum of 128 characters.',
'min_length': 'Password allows a minimum of 8 characters.',
'invalid': 'Password must contain at least 1 letter, '
'a number and a special character',
})
confirm_password = serializers.CharField(
style={'input_type': 'password', 'placeholder': 'Confirm Password'})
243 changes: 243 additions & 0 deletions authors/apps/authentication/templates/reset_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Password Reset</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
/**
* Google webfonts. Recommended to include the .woff version for cross-client compatibility.
*/
@media screen {
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/ODelI1aHBYDBqgeIAH2zlBM0YzuT7MdOe03otPbuUS0.woff) format('woff');
}
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 700;
src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/toadOcfmlt9b38dHJxOBGFkQc6VGVFSmCnC_l7QZG60.woff) format('woff');
}
}
/**
* Avoid browser level font resizing.
* 1. Windows Mobile
* 2. iOS / OSX
*/
body,
table,
td,
a {
-ms-text-size-adjust: 100%; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/**
* Remove extra space added to tables and cells in Outlook.
*/
table,
td {
mso-table-rspace: 0pt;
mso-table-lspace: 0pt;
}
/**
* Better fluid images in Internet Explorer.
*/
img {
-ms-interpolation-mode: bicubic;
}
/**
* Remove blue links for iOS devices.
*/
a[x-apple-data-detectors] {
font-family: inherit !important;
font-size: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
color: inherit !important;
text-decoration: none !important;
}
/**
* Fix centering issues in Android 4.4.
*/
div[style*="margin: 16px 0;"] {
margin: 0 !important;
}
body {
width: 100% !important;
height: 100% !important;
padding: 0 !important;
margin: 0 !important;
}
/**
* Collapse table borders to avoid space between cells.
*/
table {
border-collapse: collapse !important;
}
a {
color: #1a82e2;
}
img {
height: auto;
line-height: 100%;
text-decoration: none;
border: 0;
outline: none;
}
</style>

</head>
<body style="background-color: #e9ecef;">

<!-- start preheader -->
<div class="preheader" style="display: none; max-width: 0; max-height: 0; overflow: hidden; font-size: 1px; line-height: 1px; color: #fff; opacity: 0;">
Hello, <b>{{ username }}</b>.We received a password reset request for your account. Please tap the button below to reset your password.
</div>
<!-- end preheader -->

<!-- start body -->
<table border="0" cellpadding="0" cellspacing="0" width="100%">

<!-- start logo -->
<tr>
<td align="center" bgcolor="#e9ecef">
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600">
<tr>
<td align="center" valign="top" width="600">
<![endif]-->
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<!-- end logo -->

<!-- start hero -->
<tr>
<td align="center" bgcolor="#e9ecef">
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600">
<tr>
<td align="center" valign="top" width="600">
<![endif]-->
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
<tr>
<td align="left" bgcolor="#ffffff" style="padding: 36px 24px 0; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; border-top: 3px solid #d4dadf;">
<h1 style="margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -1px; line-height: 48px;">Reset Your Password</h1>
</td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<!-- end hero -->

<!-- start copy block -->
<tr>
<td align="center" bgcolor="#e9ecef">
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600">
<tr>
<td align="center" valign="top" width="600">
<![endif]-->
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">

<!-- start copy -->
<tr>
<td align="left" bgcolor="#ffffff" style="padding: 24px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">
<p style="margin: 0;">Tap the button below to reset your customer account password. If you didn't request a new password, you can safely ignore this email.</p>
</td>
</tr>
<!-- end copy -->

<!-- start button -->
<tr>
<td align="left" bgcolor="#ffffff">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" bgcolor="#ffffff" style="padding: 12px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" bgcolor="#1a82e2" style="border-radius: 6px;">
<a href="{{link}}" target="_blank" style="display: inline-block; padding: 16px 36px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;">Reset Password</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!-- end button -->

<!-- start copy -->
<tr>
<td align="left" bgcolor="#ffffff" style="padding: 24px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">
<p style="margin: 0;">If that doesn't work, copy and paste the following link in your browser:</p>
<p style="margin: 0;"><a href="{{link}}" target="_blank">{{link}}</a></p>
</td>
</tr>
<!-- end copy -->

<!-- start copy -->
<tr>
<td align="left" bgcolor="#ffffff" style="padding: 24px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-bottom: 3px solid #d4dadf">
<p style="margin: 0;">Cheers,<br> The Author's Haven Team.</p>
</td>
</tr>
<!-- end copy -->

</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<!-- end copy block -->

<!-- start footer -->
<tr>
<td align="center" bgcolor="#e9ecef" style="padding: 24px;">
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600">
<tr>
<td align="center" valign="top" width="600">
<![endif]-->
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">

<!-- start permission -->
<tr>
<td align="center" bgcolor="#e9ecef" style="padding: 12px 24px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px; color: #666;">
<p style="margin: 0;">You received this email because we received a request for a password reset for your account. If you didn't request a password reset you can safely ignore this email.</p>
</td>
</tr>
<!-- end permission -->

</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<!-- end footer -->

</table>
<!-- end body -->

</body>
9 changes: 7 additions & 2 deletions authors/apps/authentication/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import path
from .views import (
LoginAPIView, RegistrationAPIView, UserRetrieveUpdateAPIView
LoginAPIView, RegistrationAPIView, UserRetrieveUpdateAPIView,
PasswordReset, PasswordDone
)

""" Django 2.0 requires the app_name variable set when using include
Expand All @@ -11,5 +12,9 @@
urlpatterns = [
path('user/', UserRetrieveUpdateAPIView.as_view()),
path('users/', RegistrationAPIView.as_view(), name="signup_url"),
path('users/login/', LoginAPIView.as_view(), name="login_url")
path('users/login/', LoginAPIView.as_view(), name="login_url"),
path('users/password-reset/', PasswordReset.as_view(),
name="password_reset"),
path('users/password-done/<str:token>', PasswordDone.as_view(),
name="password_done"),
]
Loading

0 comments on commit 1b77025

Please sign in to comment.