Skip to content

Commit

Permalink
Chore(cleanup) cleanup account activation view class
Browse files Browse the repository at this point in the history
-remove multiple return statements

[Delivers #161883256]
  • Loading branch information
Edward-K1 committed Nov 22, 2018
1 parent c38810e commit 434fa91
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 171 deletions.
80 changes: 0 additions & 80 deletions authors/apps/articles/migrations/0001_initial.py

This file was deleted.

Empty file.
5 changes: 5 additions & 0 deletions authors/apps/authentication/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def clean_byte_str(byte_str):
"""
Removes b'' from bytes converted to strings
"""
return byte_str[2:-1]
36 changes: 0 additions & 36 deletions authors/apps/authentication/migrations/0001_initial.py

This file was deleted.

25 changes: 13 additions & 12 deletions authors/apps/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
UserSerializer, ResetPasswordSerializer)
from .models import User
from .validation import validate
from .helpers import clean_byte_str
from django.http import HttpResponseRedirect
import base64

Expand Down Expand Up @@ -41,7 +42,7 @@ def post(self, request):
token = serializer.data['token']

encoded_url = str(base64.b64encode(bytes(redirect_url, 'utf-8')))
encoded_url = encoded_url[2:-1] # remove b''
encoded_url = clean_byte_str(encoded_url)
redirect_str = token + "$" + str(encoded_url)
content = "Thank you for registering with Authors Haven.\
Follow this link to activate your account {}{}{}/".format(
Expand Down Expand Up @@ -164,7 +165,7 @@ def get(self, request, token):
cleantoken = token
if '$' in str(token):
redirect_url = str(base64.b64decode((token.rsplit('$', 1)[1])))
redirect_url = redirect_url[2:-1]
redirect_url = clean_byte_str(redirect_url)
cleantoken = str((token.rsplit('$')[0]))
try:

Expand All @@ -175,10 +176,7 @@ def get(self, request, token):
user.is_verified = True
user.save()

if redirect_url:
return HttpResponseRedirect(redirect_url)

return Response({
return self.redirect_if_true(redirect_url) or Response({
"message":
"Your account has been successfully " +
"activated. Complete profile",
Expand All @@ -187,18 +185,21 @@ def get(self, request, token):
},
status=status.HTTP_200_OK)

if redirect_url:
return HttpResponseRedirect(redirect_url)

return Response(
return self.redirect_if_true(redirect_url) or Response(
{
"message": "Account already activated. Please login"
},
status=status.HTTP_200_OK)

except Exception:
return Response({

except Exception as e:

return self.redirect_if_true(redirect_url) or Response({
"message":
"Sorry. Activation link " + "either expired or is invalid"
},
status=status.HTTP_400_BAD_REQUEST)

def redirect_if_true(self, redirect_url):
if redirect_url:
return HttpResponseRedirect(redirect_url)
43 changes: 0 additions & 43 deletions authors/apps/profiles/migrations/0001_initial.py

This file was deleted.

Empty file.

0 comments on commit 434fa91

Please sign in to comment.