Merge branch '10-napraviti-dummy-payment-page' into 'master'

Resolve "Napraviti dummy payment page"

Closes #10

See merge request kbr4/riskletpy!10
This commit was merged in pull request #59.
This commit is contained in:
2025-02-21 06:23:52 +00:00
9 changed files with 92 additions and 15 deletions

View File

@@ -1,8 +1,10 @@
{% extends "base_login.html" %} {% extends "base.html" %}
{%block content%}
<h2>Link has expired! </h2> <h2>Link has expired! </h2>
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
<button type="submit">Resend link</button> <button type="submit">Resend link</button>
</form>
</form>
{% endblock %}

View File

@@ -1,5 +1,11 @@
{% extends "base_login.html" %} {% extends "base.html" %}
{%block content%}
<div class="out-risk-management">
<div class="risk-management">
<h1>Email Confirmed!</h1>
<p>Your email {{ email }} has been successfully verified.</p>
</div>
</div>
<h1>Email Confirmed!</h1> {%endblock%}
<p>Your email {{ email }} has been successfully verified.</p>

View File

@@ -4,7 +4,7 @@ from .models import EmailConfirmation
import uuid import uuid
from django.conf import settings from django.conf import settings
from django.utils.timezone import now from django.utils.timezone import now
from backend.core.models import Document, Organization
def send_confirmation_email(email): def send_confirmation_email(email):
confirmation, created = EmailConfirmation.objects.get_or_create(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}", message=f"Please click on the link to confirm your e-mail address: {confirmation_link}",
from_email= settings.EMAIL_HOST_USER, from_email= settings.EMAIL_HOST_USER,
recipient_list=[email] recipient_list=[email]
) )
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,
)

View File

@@ -17,13 +17,10 @@ def confirm_email(request, uuid):
confirmation = get_object_or_404(EmailConfirmation, uuid=uuid) confirmation = get_object_or_404(EmailConfirmation, uuid=uuid)
if confirmation.is_expired(): 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) task = create_document_for_organization.delay(confirmation.email)
print(f"Task ID: {task.id}") return render(request, 'accounts/confirmation_success.html', {'email': confirmation.email})
return HttpResponse("Email is confirmed")
def resend_confirmation(request,email): def resend_confirmation(request,email):
if request.method == 'POST': if request.method == 'POST':

View File

@@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% block content %}
<div class="out-risk-management">
<div class="risk-management">
<h2>Payment</h2>
<p>Click the button below to pay and access your document.</p>
<form method="post">
{% csrf_token %}
<button class="btn-bl" type="submit">Pay</button>
</form>
</div>
</div>
{% endblock %}

View File

@@ -11,4 +11,5 @@ urlpatterns = [
# url document/ recieves a parameter named 'uuid' and passes it to the view # url document/ recieves a parameter named 'uuid' and passes it to the view
path('document/<uuid:document_id>/', v.document, name='document'), path('document/<uuid:document_id>/', v.document, name='document'),
path('preview/<str:name>/', v.template_preview, name='template_preview'), path('preview/<str:name>/', v.template_preview, name='template_preview'),
path("payment/", v.payment_page, name="payment_page"),
] ]

View File

@@ -5,7 +5,7 @@ from .forms import OrganizationForm
from .models import Organization,Document,Risk, DocumentTemplate from .models import Organization,Document,Risk, DocumentTemplate
from backend.core.utils import get_top_risk from backend.core.utils import get_top_risk
from django.urls import reverse 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.contrib.admin.views.decorators import staff_member_required
# @login_required # @login_required
@@ -56,4 +56,17 @@ def document(request, document_id):
def template_preview(request, name): def template_preview(request, name):
template = get_object_or_404(DocumentTemplate, name=name) template = get_object_or_404(DocumentTemplate, name=name)
parsed_template = template.to_dict() parsed_template = template.to_dict()
return render(request, 'template_preview.html', {'template': parsed_template}) 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})

View File

@@ -9,3 +9,11 @@ Faker==33.0.0
isort==5.13.2 isort==5.13.2
python-decouple==3.8 python-decouple==3.8
psycopg2-binary==2.9.10 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

12
start_services.sh Executable file
View File

@@ -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