2024-12-29 03:44:52 +01:00
|
|
|
from django.urls import reverse_lazy
|
|
|
|
|
from django.views.generic import CreateView
|
|
|
|
|
from backend.accounts.forms import SignupForm
|
2025-02-13 16:38:29 +01:00
|
|
|
from .models import EmailConfirmation
|
|
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
|
|
from django.http import HttpResponse
|
2025-02-17 20:36:59 +01:00
|
|
|
from backend.accounts.utils import send_confirmation_email
|
2025-02-14 19:39:23 +01:00
|
|
|
from .tasks import create_document_for_organization
|
2025-06-09 18:03:51 +02:00
|
|
|
from backend.core.models import Organization, Document
|
2024-12-29 03:44:52 +01:00
|
|
|
|
|
|
|
|
class SignUpView(CreateView):
|
|
|
|
|
form_class = SignupForm
|
|
|
|
|
success_url = reverse_lazy('login')
|
|
|
|
|
template_name = 'accounts/signup.html'
|
2025-02-13 16:38:29 +01:00
|
|
|
|
|
|
|
|
|
2025-02-14 17:52:51 +01:00
|
|
|
def confirm_email(request, uuid):
|
2025-02-13 16:38:29 +01:00
|
|
|
confirmation = get_object_or_404(EmailConfirmation, uuid=uuid)
|
|
|
|
|
|
|
|
|
|
if confirmation.is_expired():
|
2025-02-21 00:53:18 +01:00
|
|
|
return render(request, 'accounts/confirmation_expired.html', {'email': confirmation.email})
|
2025-02-14 17:52:51 +01:00
|
|
|
|
2025-06-09 18:03:51 +02:00
|
|
|
if confirmation.confirmed:
|
|
|
|
|
return render(request, 'accounts/confirmation_success.html', {'email': confirmation.email})
|
|
|
|
|
|
|
|
|
|
confirmation.confirmed = True
|
|
|
|
|
confirmation.save()
|
|
|
|
|
|
|
|
|
|
org = Organization.objects.filter(email=confirmation.email).first()
|
|
|
|
|
if org and Document.objects.filter(organization=org).exists():
|
|
|
|
|
return render(request, 'accounts/confirmation_success.html', {'email': confirmation.email})
|
|
|
|
|
else:
|
|
|
|
|
task = create_document_for_organization.delay(confirmation.email)
|
|
|
|
|
return render(request, 'accounts/confirmation_success.html', {'email': confirmation.email})
|
2025-02-13 16:38:29 +01:00
|
|
|
|
|
|
|
|
def resend_confirmation(request,email):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
send_confirmation_email(email)
|
|
|
|
|
return HttpResponse("Confirmation email resent")
|