added email validation to purchase_email view
This commit is contained in:
@@ -5,6 +5,7 @@ import json
|
||||
|
||||
from django.db.models import Q
|
||||
from django.core import serializers
|
||||
from django.core.validators import EmailValidator, validate_email
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.mail import EmailMessage
|
||||
@@ -259,7 +260,6 @@ def purchase_email(request):
|
||||
# check data
|
||||
if request.user.is_anonymous and 'email' not in data:
|
||||
return Response({"error": "Anonymous users must include an email parameter value"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||
|
||||
try:
|
||||
for param in ('telephone', 'company', 'product', 'comment'):
|
||||
assert(param in data.keys())
|
||||
@@ -271,7 +271,11 @@ def purchase_email(request):
|
||||
else:
|
||||
email = request.user.email
|
||||
telephone = data.get('telephone')
|
||||
|
||||
# validate email
|
||||
try:
|
||||
validate_email(email)
|
||||
except:
|
||||
return Response({"error": "Value for email is not valid"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||
# get company
|
||||
company = Company.objects.filter(id=data['company']).first()
|
||||
if not company:
|
||||
|
||||
Reference in New Issue
Block a user