EgbieAndersonUku1 / Fullstack-fruit-and-veg

Fullstack Fruit & Veg Shop: A web application developed with HTML, CSS, and JavaScript for the frontend, and Django for the backend. Features include user authentication, a product catalogue, shopping cart functionality, and order management. and much more
https://fullstack-fruit-and-veg.vercel.app
0 stars 0 forks source link

SubscriptionUpdate "Fix issue allowing duplicate email subscriptions #42

Closed EgbieAndersonUku1 closed 1 month ago

EgbieAndersonUku1 commented 1 month ago

Added a try-except block in views.py to prevent the model from creating a subscription when an email already exists in the database.

Previous Code:

NewsletterSubscription.objects.filter(user=user, email=email.lower()).exists()

Updated Code:

try:
    NewsletterSubscription.objects.create(user=user, email=email)
except IntegrityError:  # Except block to catch the error
    error_msg = \"A user with that email already exists.\"

return is_valid, error_msg

Workflow Users can subscribe only if they have not previously registered with that email address. If they have already subscribed, they will receive an alert indicating that they cannot use that email again. If the subscription is successful, they will be shown a tailored message confirming their subscription.

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **fullstack-fruit-and-veg** | ⬜️ Ignored ([Inspect](https://vercel.com/egbies-projects/fullstack-fruit-and-veg/4LHHHVUCMeVqaWVKndxCK4zrrX9C)) | | | Oct 24, 2024 2:17am |