user activation now redirects to home
This commit is contained in:
@@ -171,3 +171,6 @@ MAP_WIDGETS = {
|
|||||||
),
|
),
|
||||||
"GOOGLE_MAP_API_KEY": os.getenv('GOOGLE_MAP_API_KEY')
|
"GOOGLE_MAP_API_KEY": os.getenv('GOOGLE_MAP_API_KEY')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ACTIVATION_REDIRECT URL
|
||||||
|
ACTIVATION_REDIRECT = os.getenv('ACTIVATION_REDIRECT')
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from django.test import TestCase
|
|||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
@@ -492,6 +493,21 @@ class ActivateUserTest(APITestCase):
|
|||||||
|
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
|
||||||
|
# assertions
|
||||||
|
self.assertEquals(response.status_code, 302)
|
||||||
|
self.assertEquals(response.url, settings.ACTIVATION_REDIRECT)
|
||||||
|
|
||||||
|
def test_correct_activation_no_redirect(self):
|
||||||
|
# set ACTIVATION_REDIRECT to ''
|
||||||
|
settings.ACTIVATION_REDIRECT = ''
|
||||||
|
# create values
|
||||||
|
uid = urlsafe_base64_encode(force_bytes(self.user.pk))
|
||||||
|
token = account_activation_token.make_token(self.user)
|
||||||
|
|
||||||
|
url = f'/activate/{uid}/{token}/'
|
||||||
|
|
||||||
|
response = self.client.get(url)
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
self.assertEquals(response.status_code, 200)
|
self.assertEquals(response.status_code, 200)
|
||||||
self.assertTrue(self.user.email in str(response.content))
|
self.assertTrue(self.user.email in str(response.content))
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ from django.utils.http import urlsafe_base64_decode
|
|||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.contrib.gis.geos import Point
|
from django.contrib.gis.geos import Point
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
@@ -190,6 +192,8 @@ def activate_user(request, uidb64, token):
|
|||||||
# activate user
|
# activate user
|
||||||
user.is_active = True
|
user.is_active = True
|
||||||
user.save()
|
user.save()
|
||||||
|
if settings.ACTIVATION_REDIRECT:
|
||||||
|
return redirect(settings.ACTIVATION_REDIRECT)
|
||||||
return Response(f"Tu cuenta de usuario {user.email} ha sido activada")
|
return Response(f"Tu cuenta de usuario {user.email} ha sido activada")
|
||||||
else:
|
else:
|
||||||
return Response({"error": f"Tu token de verificacion no coincide con ningún usuario registrado"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
return Response({"error": f"Tu token de verificacion no coincide con ningún usuario registrado"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||||
|
|||||||
@@ -15,3 +15,5 @@ WC_KEY = ''
|
|||||||
WC_SECRET = ''
|
WC_SECRET = ''
|
||||||
# GOOGLE MAPS
|
# GOOGLE MAPS
|
||||||
GOOGLE_MAP_API_KEY = ''
|
GOOGLE_MAP_API_KEY = ''
|
||||||
|
# USER ACTIVATION REDIRECTION
|
||||||
|
ACTIVATION_REDIRECT = ''
|
||||||
Reference in New Issue
Block a user