From 6551e81be8b7637378dd3e3c9c00c595ff639338 Mon Sep 17 00:00:00 2001 From: Guillim Date: Mon, 17 Jun 2019 18:27:55 +0200 Subject: [PATCH] We create the funciton that validates an email address checking if the token if correct. --- app/authentification/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/authentification/utils.py diff --git a/app/authentification/utils.py b/app/authentification/utils.py new file mode 100644 index 00000000..9a6ab5e7 --- /dev/null +++ b/app/authentification/utils.py @@ -0,0 +1,21 @@ +from django.shortcuts import render +from django.shortcuts import redirect +from django.contrib.auth import login +from django.utils.encoding import force_text +from django.utils.http import urlsafe_base64_decode +from .tokens import account_activation_token +from django.contrib.auth.models import User + +def activate(request, uidb64, token): + try: + uid = force_text(urlsafe_base64_decode(uidb64)) + user = User.objects.get(pk=uid) + except(TypeError, ValueError, OverflowError, User.DoesNotExist): + user = None + if user is not None and account_activation_token.check_token(user, token): + user.is_active = True + user.save() + login(request, user, backend='django.contrib.auth.backends.ModelBackend') + return redirect('projects') + else: + return render(request, 'validate_mail_address_invalid.html')