email verification sent for users loaded thru CSV

This commit is contained in:
Sam
2021-02-05 13:11:09 +00:00
parent 75234953c0
commit a9cb7cedd6
7 changed files with 67 additions and 3 deletions

View File

@@ -8,11 +8,13 @@ from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth import get_user_model
from django.core import serializers
from django.utils.http import urlsafe_base64_decode
from django.utils.encoding import force_text
from rest_framework import status
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.permissions import IsAdminUser, IsAuthenticated, AllowAny
from rest_framework.generics import UpdateAPIView
from rest_framework.decorators import api_view, permission_classes
@@ -20,6 +22,7 @@ from companies.models import Company
from . import models
from . import serializers as core_serializers
from . import utils
from back_latienda.permissions import CustomUserPermissions, YourOwnUserPermissions
@@ -142,7 +145,8 @@ def load_coop_managers(request):
coop_counter += 1
coop_user = User.objects.create_user(email=row['email'], company=coop, role='COOP_MANAGER', is_active=False)
# TODO: send confirmation email
# send confirmation email
utils.send_verification_email(request, coop_user)
logging.info(f"Created User: {coop_user}")
user_counter += 1
except Exception as e:
@@ -152,3 +156,20 @@ def load_coop_managers(request):
except Exception as e:
return Response({"errors": {"details": str(type(e))}})
@api_view(['GET',])
@permission_classes([AllowAny,])
def activate_user(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):
# activate user
user.is_active = True
user.save()
return HttpResponse(f"Tu cuenta de usuario {request.user.email} ha sido activada")
else:
return HttpResponse(f"Tu token de verificacion no coincide con ningún usuario registrado")