-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
257 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
source env/bin/activate | ||
export DB_NAME="Your DB" | ||
export DB_USER="DB User" | ||
export DB_PASS="DB Password" | ||
export DB_HOST="localhost" | ||
export DB_PORT="DB port" | ||
export EMAIL_HOST_USER="host username" | ||
export EMAIL_HOST_PASSWORD="email password" | ||
export PASSWORD_RESET_URL="127.0.0.1:8000/api" | ||
export DEFAULT_FROM_EMAIL="senders email" | ||
export SECRET_KEY="enter your secret key" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Authors Haven account verification</title> | ||
<meta name="description" content="Our first page"> | ||
<meta name="keywords" content="html tutorial template"> | ||
</head> | ||
|
||
|
||
<body> | ||
<div id="div-page" style="border: 2px solid #86C232;border-radius: 25px;width: 30em;padding: 25px;margin: 5em;text-align: justify; border-width: thick"> | ||
|
||
<h1 style="line-height: 35px;text-align: center; color: #86C232;"> | ||
Authors Haven | ||
</h1> | ||
<h1 style="line-height: 35px;text-align: center;"> | ||
Hello <span id="username" style="color: #23bebe;">{{username}}</span> | ||
</h1> | ||
|
||
<div id="div-content" style="line-height: 26px;"> | ||
<p style="text-align: center;">Your requested for password reset!</p> | ||
<p style="text-align: center;">Please reset your password by clicking the button below</p> | ||
<div style="margin-top: 7%;"> | ||
<a id="confirm-link" href="{{link}}" style="background-color: | ||
#23bebe; color:#fff;padding: 0.4em;font-size: 2em;text-decoration: none;margin-left: 19%;">Reset Password</a> | ||
</div> | ||
<br> | ||
<p style="text-align: center;">Kindly note that the link expires in exactly one day as from {{time}}</p> | ||
|
||
</div> | ||
</div> | ||
|
||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import json | ||
import jwt | ||
from datetime import datetime, timedelta | ||
from django.conf import settings | ||
from django.urls import reverse | ||
from rest_framework.views import status | ||
from rest_framework.test import APITestCase, APIClient | ||
|
||
|
||
class ResetPasswordTestCase(APITestCase): | ||
def setUp(self): | ||
self.client = APIClient() | ||
self.password_reset_url = reverse('authentication:passwordreset') | ||
self.signup_url = reverse('authentication:auth-register') | ||
self.signup_data = { | ||
"user": { | ||
"username": "MaryGigz", | ||
"email": "chegemaggie1@gmail.com", | ||
"password": "g@_Gigz-2416" | ||
}} | ||
self.email = { | ||
"email": "chegemaggie1@gmail.com" | ||
} | ||
self.email_not_registered = { | ||
"email": "kenna@gmail.com" | ||
} | ||
self.test_update_password_data = { | ||
"password": "Jake@1234", | ||
"confirm_password": "Jake@1234" | ||
|
||
} | ||
|
||
def register(self): | ||
register = self.client.post(self.signup_url, self.signup_data, | ||
format='json') | ||
self.assertEqual(register.status_code, status.HTTP_201_CREATED) | ||
return register | ||
|
||
@staticmethod | ||
def create_url(email): | ||
"""create a url with the token, this is done after user receives an email""" | ||
token = jwt.encode({"email": email, | ||
"iat": datetime.now(), | ||
"exp": datetime.utcnow() + timedelta(minutes=5)}, | ||
settings.SECRET_KEY, | ||
algorithm='HS256').decode() | ||
password_reset_url = reverse("authentication:passwordresetdone", | ||
kwargs={"token": token}) | ||
return password_reset_url | ||
|
||
def test_reset_password(self): | ||
"""Test user can reset the password""" | ||
self.register() | ||
response = self.client.put(self.create_url("chegemaggie1@gmail.com"), | ||
self.test_update_password_data, | ||
format="json") | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_email_not_registered(self): | ||
"""Test if user that is not registered can get the email""" | ||
response = self.client.post(self.password_reset_url, | ||
self.email_not_registered, | ||
format="json") | ||
self.assertEqual(response. status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(json.loads(response.content), {'errors': {'email': | ||
['User with this email does not exist.']}}) | ||
|
||
def test_send_email(self): | ||
"""First register a new user and check if user is registered""" | ||
self.register() | ||
response = self.client.post(self.password_reset_url, | ||
self.email, | ||
format="json") | ||
self.assertEqual(response. status_code, status.HTTP_200_OK) | ||
self.assertEqual(json.loads(response.content), {'message': | ||
'Successfully sent.Check your email'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters