Skip to content

Commit

Permalink
bug(social-auth): Fixes social login bug
Browse files Browse the repository at this point in the history
- Set is_verified flag to true for socially logged in users
[Starts #164201550]
  • Loading branch information
Allan690 committed Feb 25, 2019
1 parent cd27266 commit fac98e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions authors/apps/authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from builtins import BaseException

from datetime import datetime, timedelta

import jwt
Expand Down Expand Up @@ -26,6 +28,7 @@
EmailCheckSerializer, PasswordResetSerializer, ActivateSerializer,
)
from .backends import get_jwt_token
activation_url = os.getenv('ACTIVATION_URL')


class RegistrationAPIView(CreateAPIView):
Expand All @@ -36,7 +39,7 @@ class RegistrationAPIView(CreateAPIView):

def post(self, request):
user = request.data.get('user', {})

# The create serializer, validate serializer, save serializer pattern
# below is common and you will see it a lot throughout this course and
# your own work later on. Get familiar with it.
Expand Down Expand Up @@ -70,7 +73,7 @@ def post(self, request):
# create activation link
activation_link = "{scheme}://{host}{route}".format(
scheme=request.scheme,
host=request.get_host(),
host=activation_url,
route=url
)
username = user_to_activate.username
Expand Down Expand Up @@ -192,7 +195,7 @@ def post(self, request):
"exp": datetime.utcnow() + timedelta(hours=1)},
os.getenv('SECRET_KEY'), algorithm='HS256').decode()

hosting = request.get_host()
hosting = activation_url

my_link = \
'https://' + hosting + '/api/users/password-done/{}'.format(token)
Expand Down Expand Up @@ -271,10 +274,12 @@ def create(self, request, *args, **kwargs):
return Response(message, status=status.HTTP_400_BAD_REQUEST)
try:
user = backend.do_auth(token)
user.is_verified = True
except BaseException:
return Response({"error": "Invalid token."},
status=status.HTTP_400_BAD_REQUEST)
serializer = UserSerializer(user)
serializer_data = serializer.data
serializer_data["token"] = get_jwt_token(user)
return Response(serializer_data, status=status.HTTP_200_OK)

6 changes: 3 additions & 3 deletions authors/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
]

MIDDLEWARE_CLASSES = (
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.BrokenLinkEmailsMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.BrokenLinkEmailsMiddleware',
'django.middleware.common.CommonMiddleware',
)
CORS_ORIGIN_ALLOW_ALL = True

Expand Down

0 comments on commit fac98e8

Please sign in to comment.