Skip to content

Commit

Permalink
Merge pull request #53 from andela/bg-fix-passwordreset-frontend-redi…
Browse files Browse the repository at this point in the history
…rect

bg-fix-password-reset-email-redirect-link
  • Loading branch information
pbkabali authored Mar 21, 2019
2 parents d4cd1a0 + 8c2f38b commit d134bb6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
},
"CLOUDAMQP_URL": {
"required": true
},
"FRONT_END_URL": {
"required": true
}
},
"formation": {},
Expand Down
4 changes: 2 additions & 2 deletions authors/apps/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def post(self, request):
serializer.is_valid(raise_exception=True)
user_email = user.get("email", None)
PasswordResetManager(request).send_password_reset_email(user_email)
msg = "An email has been sent to your \
mailbox with instructions to reset your password"
msg = ("An email has been sent to your "
"mailbox with instructions to reset your password")
return Response(
{
"message": msg,
Expand Down
7 changes: 5 additions & 2 deletions authors/apps/core/password_reset_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ..authentication.models import UserManager, User
from rest_framework import serializers
import jwt
import os
import datetime
from django.conf import settings
from django.template.loader import render_to_string
Expand Down Expand Up @@ -44,10 +45,12 @@ def prepare_password_reset_email(self, email):
settings.SECRET_KEY,
algorithm='HS256'
)
domain = f"{os.getenv('FRONT_END_URL')}"
token = self.encoded_token.decode('utf-8')
link = f'{domain}reset-password/{token}/'
self.context = {
'username': user.username,
'reset_link': self.password_reset_url +
self.encoded_token.decode('utf-8') + '/'
'reset_link': link
}
self.email_body = render_to_string(
'password_reset_email.txt', self.context)
Expand Down

0 comments on commit d134bb6

Please sign in to comment.