From ff6b525e18cf4a78979965f70af04055be172aed Mon Sep 17 00:00:00 2001 From: Amir Date: Fri, 21 Feb 2025 14:58:02 +0100 Subject: [PATCH] Konflikt resen --- backend/accounts/tasks.py | 6 +++- .../accounts/confirmation_expired.html | 8 +++-- .../accounts/confirmation_success.html | 12 +++++-- backend/accounts/utils.py | 28 +++++++++++++-- backend/accounts/views.py | 7 ++-- backend/core/templates/payment.html | 14 ++++++++ backend/core/urls.py | 2 ++ backend/core/views.py | 34 +++++++++++++------ requirements.txt | 8 +++++ start_services.sh | 12 +++++++ 10 files changed, 107 insertions(+), 24 deletions(-) create mode 100644 backend/core/templates/payment.html create mode 100755 start_services.sh diff --git a/backend/accounts/tasks.py b/backend/accounts/tasks.py index 56cf39a..0b22d94 100644 --- a/backend/accounts/tasks.py +++ b/backend/accounts/tasks.py @@ -2,6 +2,7 @@ from celery import shared_task from backend.core.models import Organization, Document, Risk, Control, DocumentRiskControl from backend.core.utils import get_top_risk, get_controls_for_risk from django.shortcuts import get_object_or_404, render +from .utils import send_payment_email @shared_task @@ -49,4 +50,7 @@ def create_document_for_organization(confirmation_email): controls_content += "\n" - document.add_segment('body', controls_content) \ No newline at end of file + document.add_segment('body', controls_content) + + + send_payment_email(confirmation_email) \ No newline at end of file diff --git a/backend/accounts/templates/accounts/confirmation_expired.html b/backend/accounts/templates/accounts/confirmation_expired.html index 7624b9a..66e6a9b 100644 --- a/backend/accounts/templates/accounts/confirmation_expired.html +++ b/backend/accounts/templates/accounts/confirmation_expired.html @@ -1,8 +1,10 @@ -{% extends "base_login.html" %} - +{% extends "base.html" %} +{%block content%}

Link has expired!

{% csrf_token %} -
\ No newline at end of file + + +{% endblock %} \ No newline at end of file diff --git a/backend/accounts/templates/accounts/confirmation_success.html b/backend/accounts/templates/accounts/confirmation_success.html index 32a64d0..a26424f 100644 --- a/backend/accounts/templates/accounts/confirmation_success.html +++ b/backend/accounts/templates/accounts/confirmation_success.html @@ -1,5 +1,11 @@ -{% extends "base_login.html" %} +{% extends "base.html" %} +{%block content%} +
+
+

Email Confirmed!

+

Your email {{ email }} has been successfully verified.

+
+
-

Email Confirmed!

-

Your email {{ email }} has been successfully verified.

+{%endblock%} diff --git a/backend/accounts/utils.py b/backend/accounts/utils.py index 6ed5ff0..c9a6ba8 100644 --- a/backend/accounts/utils.py +++ b/backend/accounts/utils.py @@ -4,7 +4,7 @@ from .models import EmailConfirmation import uuid from django.conf import settings from django.utils.timezone import now - +from backend.core.models import Document, Organization def send_confirmation_email(email): confirmation, created = EmailConfirmation.objects.get_or_create(email=email) @@ -21,4 +21,28 @@ def send_confirmation_email(email): message=f"Please click on the link to confirm your e-mail address: {confirmation_link}", from_email= settings.EMAIL_HOST_USER, recipient_list=[email] - ) \ No newline at end of file + ) + +def send_payment_email(email): + organization = Organization.objects.get(email=email) + document = Document.objects.get(organization=organization) + + payment_link = f"http://127.0.0.1:8000{reverse('core:payment_page')}?email={email}" + + send_mail( + subject="Complete your payment", + message=f"Click the link to proceed with payment: {payment_link}", + from_email=settings.EMAIL_HOST_USER, + recipient_list=[email], + fail_silently=False, + ) + +def send_document_email(email, document_link): + send_mail( + subject="Your Document is Ready", + message=f"You can access your document at any time here: {document_link}", + from_email=settings.EMAIL_HOST_USER, + recipient_list=[email], + fail_silently=False, + ) + diff --git a/backend/accounts/views.py b/backend/accounts/views.py index c644ca5..901f3ea 100644 --- a/backend/accounts/views.py +++ b/backend/accounts/views.py @@ -17,13 +17,10 @@ def confirm_email(request, uuid): confirmation = get_object_or_404(EmailConfirmation, uuid=uuid) if confirmation.is_expired(): - return render(request, 'confirmation_expired.html', {'email': confirmation.email}) + return render(request, 'accounts/confirmation_expired.html', {'email': confirmation.email}) task = create_document_for_organization.delay(confirmation.email) - print(f"Task ID: {task.id}") - - - return HttpResponse("Email is confirmed") + return render(request, 'accounts/confirmation_success.html', {'email': confirmation.email}) def resend_confirmation(request,email): if request.method == 'POST': diff --git a/backend/core/templates/payment.html b/backend/core/templates/payment.html new file mode 100644 index 0000000..ab52439 --- /dev/null +++ b/backend/core/templates/payment.html @@ -0,0 +1,14 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+

Payment

+

Click the button below to pay and access your document.

+
+ {% csrf_token %} + +
+
+
+{% endblock %} \ No newline at end of file diff --git a/backend/core/urls.py b/backend/core/urls.py index 1b67d6c..9b5d2ea 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -11,4 +11,6 @@ urlpatterns = [ # url document/ recieves a parameter named 'uuid' and passes it to the view path('document//', v.document, name='document'), path('preview//', v.template_preview, name='template_preview'), + path("payment/", v.payment_page, name="payment_page"), + ] diff --git a/backend/core/views.py b/backend/core/views.py index c283d75..701cd67 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -3,14 +3,15 @@ import yaml from django.shortcuts import render, redirect , get_object_or_404 from .forms import OrganizationForm -from .models import Organization,Document,Risk, DocumentTemplate,DocumentRiskControl,Control +from .models import Organization,Document,Risk, DocumentTemplate,DocumentRiskControl from backend.core.utils import get_top_risk from django.urls import reverse -from backend.accounts.utils import send_confirmation_email +from backend.accounts.utils import send_confirmation_email, send_document_email from django.contrib.admin.views.decorators import staff_member_required from django.template import Template, Context + # @login_required # def index(request): # return HttpResponse('

Django

Página simples.

') @@ -45,13 +46,6 @@ def signup(request): def thankyou(request): return render(request, 'thankyou.html') -@staff_member_required -def template_preview(request, name): - template = get_object_or_404(DocumentTemplate, name=name) - parsed_template = template.to_dict() - return render(request, 'template_preview.html', {'template': parsed_template}) - - def document(request, document_id): document = get_object_or_404(Document, id=document_id) risks = ( @@ -98,4 +92,24 @@ def document(request, document_id): django_template = Template(content) rendered_content += django_template.render(Context(context)) - return render(request, 'document.html', {'rendered_html': rendered_content}) \ No newline at end of file + return render(request, 'document.html', {'rendered_html': rendered_content}) + + +@staff_member_required +def template_preview(request, name): + template = get_object_or_404(DocumentTemplate, name=name) + parsed_template = template.to_dict() + return render(request, 'template_preview.html', {'template': parsed_template}) + +def payment_page(request): + email = request.GET.get("email") + organization = Organization.objects.get(email=email) + document = Document.objects.get(organization=organization) + document_link = f"http://127.0.0.1:8000/document/{document.id}/" + + if request.method == "POST": + send_document_email(email, document_link) + return redirect(document_link) + + return render(request, "payment.html", {"email": email}) + diff --git a/requirements.txt b/requirements.txt index de81b6c..7cadb9d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,11 @@ Faker==33.0.0 isort==5.13.2 python-decouple==3.8 psycopg2-binary==2.9.10 +openai==1.63.0 +python-dotenv==1.0.1 +PyYAML==6.0.2 +celery==5.4.0 +django-celery-results==2.5.1 +redis==5.2.1 + + diff --git a/start_services.sh b/start_services.sh new file mode 100755 index 0000000..84d747e --- /dev/null +++ b/start_services.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +echo "Starting Django server..." +python3 manage.py runserver & + +echo "Starting Celery worker..." +celery -A backend worker --loglevel=info & + +echo "Starting Redis server on port 6380..." +redis-server --port 6380 & + +wait