diff --git a/back_latienda/settings/base.py b/back_latienda/settings/base.py index 0ee9a92..5298aca 100644 --- a/back_latienda/settings/base.py +++ b/back_latienda/settings/base.py @@ -171,3 +171,6 @@ MAP_WIDGETS = { ), "GOOGLE_MAP_API_KEY": os.getenv('GOOGLE_MAP_API_KEY') } + +# ACTIVATION_REDIRECT URL +ACTIVATION_REDIRECT = os.getenv('ACTIVATION_REDIRECT') diff --git a/core/tests.py b/core/tests.py index 756b05a..2ed7ca1 100644 --- a/core/tests.py +++ b/core/tests.py @@ -9,6 +9,7 @@ from django.test import TestCase from django.core import mail from django.utils.http import urlsafe_base64_encode from django.utils.encoding import force_bytes +from django.conf import settings from rest_framework.test import APITestCase from rest_framework import status @@ -492,6 +493,21 @@ class ActivateUserTest(APITestCase): 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 self.assertEquals(response.status_code, 200) self.assertTrue(self.user.email in str(response.content)) diff --git a/core/views.py b/core/views.py index cbcca9c..bc9afd0 100644 --- a/core/views.py +++ b/core/views.py @@ -11,6 +11,8 @@ from django.utils.http import urlsafe_base64_decode from django.utils.encoding import force_text from django.db import IntegrityError 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 viewsets @@ -190,6 +192,8 @@ def activate_user(request, uidb64, token): # activate user user.is_active = True user.save() + if settings.ACTIVATION_REDIRECT: + return redirect(settings.ACTIVATION_REDIRECT) return Response(f"Tu cuenta de usuario {user.email} ha sido activada") else: return Response({"error": f"Tu token de verificacion no coincide con ningĂșn usuario registrado"}, status=status.HTTP_406_NOT_ACCEPTABLE) diff --git a/example.env b/example.env index 66a53de..87e699b 100644 --- a/example.env +++ b/example.env @@ -14,4 +14,6 @@ AWS_SECRET_ACCESS_KEY_SES = '' WC_KEY = '' WC_SECRET = '' # GOOGLE MAPS -GOOGLE_MAP_API_KEY = '' \ No newline at end of file +GOOGLE_MAP_API_KEY = '' +# USER ACTIVATION REDIRECTION +ACTIVATION_REDIRECT = '' \ No newline at end of file