generated from bisco/codex-bootstrap
feat: add email confirmation and QR generation
This commit is contained in:
37
backend/bookings/emailing.py
Normal file
37
backend/bookings/emailing.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import logging
|
||||
|
||||
from django.core.mail import send_mail
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CONFIRMATION_PATH = "/api/reservations/confirm/"
|
||||
|
||||
|
||||
def build_confirmation_link(raw_confirmation_token):
|
||||
return f"{CONFIRMATION_PATH}?token={raw_confirmation_token}"
|
||||
|
||||
|
||||
def send_confirmation_email(*, reservation, raw_confirmation_token):
|
||||
confirmation_link = build_confirmation_link(raw_confirmation_token)
|
||||
subject = f"Confirm your reservation for {reservation.performance.show.title}"
|
||||
message = (
|
||||
"Thank you for your reservation request.\n\n"
|
||||
"Please confirm your reservation by opening this link:\n"
|
||||
f"{confirmation_link}\n\n"
|
||||
"If you did not request this reservation, you can ignore this email."
|
||||
)
|
||||
|
||||
try:
|
||||
send_mail(
|
||||
subject=subject,
|
||||
message=message,
|
||||
from_email=None,
|
||||
recipient_list=[reservation.email],
|
||||
fail_silently=False,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to send confirmation email for reservation %s.",
|
||||
reservation.id,
|
||||
)
|
||||
Reference in New Issue
Block a user