Skip to content

Commit

Permalink
bg(fixTokenExpired): Enable users to be login for longer than 1 hour
Browse files Browse the repository at this point in the history
- Enable users to login for longer than 1 hour

[Fixes #165273745]
  • Loading branch information
CryceTruly committed Apr 11, 2019
1 parent f388047 commit 8e0e798
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env_sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export EMAIL_USE_TLS=True
export EMAIL_HOST_USER='your email'
export EMAIL_HOST_PASSWORD='email pass'
export EMAIL_PORT=587
export FRONT_END_URL='http://localhost:8080/login'
2 changes: 1 addition & 1 deletion authors/apps/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ def token(self):
token = jwt.encode({
"username": self.username,
"email": self.email,
"exp": datetime.utcnow() + timedelta(hours=1)
"exp": datetime.utcnow() + timedelta(hours=23)
}, settings.SECRET_KEY, algorithm='HS256')
return token.decode('utf-8')
3 changes: 1 addition & 2 deletions authors/apps/authentication/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def test_can_activate_a_user(self):
response = self.client.get(self.verify_url+"?token=" +
register_response.data['token'], format='json')
self.assertEqual(
response.data['message'], 'Your Email has been verified,you can now login')
self.assertEqual(response.status_code, status.HTTP_200_OK)
response.status_code,302)

def test_user_cant_activate_with_expired_token(self):
"""Tests if a user cannot activate email with an invalid token."""
Expand Down
9 changes: 4 additions & 5 deletions authors/apps/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.contrib.sites.shortcuts import get_current_site
from .models import User
from .renderers import UserJSONRenderer
import os
from django.http import HttpResponseRedirect
from .serializers import (
LoginSerializer, RegistrationSerializer, UserSerializer,
ResetPasswordSerializer, ChangePasswordSerializer
Expand Down Expand Up @@ -98,14 +100,11 @@ def get(self, request):
return self.sendResponse("verification link is invalid")
except jwt.ExpiredSignatureError:
return self.sendResponse("verification link is expired")

user = User.objects.filter(email=payload.get('email')).first()
user.is_verified = True
user.save()
return self.sendResponse(
"Your Email has been verified,you can now login",
status.HTTP_200_OK
)
domain = os.environ.get('FRONT_END_URL','localhost')
return HttpResponseRedirect(domain)

def sendResponse(self, message, status=status.HTTP_400_BAD_REQUEST):
return Response({"message": message}, status)
Expand Down
2 changes: 1 addition & 1 deletion authors/apps/profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def user_post_save_receiver(instance, created, *args, **kwargs):
class Follow(models.Model):
follower = models.ForeignKey(User, on_delete=models.CASCADE)
followed = models.ForeignKey(Profile, on_delete=models.CASCADE)
followed_at = models.DateTimeField(default=datetime.now, blank=True)
followed_at = models.DateTimeField(auto_now_add=True, blank=True)
3 changes: 0 additions & 3 deletions authors/apps/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
from .renderers import ProfileJSONRenderer
from .serializers import \
ProfileSerializer, ProfileUpdateSerializer, FollowSerializer
import datetime


class ProfileRetrieveAPIView(generics.RetrieveAPIView):
"""
Implements user's profile endpoint.
Expand Down
24 changes: 24 additions & 0 deletions authors/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@
'localhost:8080',
'ah-aquaman-frontend-staging.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-9.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-10.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-11.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-12.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-13.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-14.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-15.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-16.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-17.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-18.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-19.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-20.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-21.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-22.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-23.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-24.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-25.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-26.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-27.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-29.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-30.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-31.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-32.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-33.herokuapp.com',
'ah-aquaman-frontend-stagi-pr-34.herokuapp.com',

)

Expand Down

0 comments on commit 8e0e798

Please sign in to comment.