Skip to content
Snippets Groups Projects
Commit 25ca62d9 authored by Piotr Mitros's avatar Piotr Mitros
Browse files

Proper e-mail address validation

parent f6787bd8
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ from django.contrib.auth.forms import PasswordResetForm ...@@ -11,7 +11,7 @@ from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.core.mail import send_mail from django.core.mail import send_mail
from django.core.validators import validate_email, validate_slug from django.core.validators import validate_email, validate_slug, ValidationError
from django.db import connection from django.db import connection
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import redirect from django.shortcuts import redirect
...@@ -148,13 +148,13 @@ def create_account(request, post_override=None): ...@@ -148,13 +148,13 @@ def create_account(request, post_override=None):
try: try:
validate_email(post_vars['email']) validate_email(post_vars['email'])
except: except ValidationError:
js['value']="Valid e-mail is required.".format(field=a) js['value']="Valid e-mail is required.".format(field=a)
return HttpResponse(json.dumps(js)) return HttpResponse(json.dumps(js))
try: try:
validate_slug(post_vars['username']) validate_slug(post_vars['username'])
except: except ValidationError:
js['value']="Username should only consist of A-Z and 0-9.".format(field=a) js['value']="Username should only consist of A-Z and 0-9.".format(field=a)
return HttpResponse(json.dumps(js)) return HttpResponse(json.dumps(js))
...@@ -307,6 +307,12 @@ def change_email_request(request): ...@@ -307,6 +307,12 @@ def change_email_request(request):
'error':'Invalid password'})) 'error':'Invalid password'}))
new_email = request.POST['new_email'] new_email = request.POST['new_email']
try:
validate_email(new_email)
except ValidationError:
return HttpResponse(json.dumps({'success':False,
'error':'Valid e-mail address required.'}))
if len(User.objects.filter(email = new_email)) != 0: if len(User.objects.filter(email = new_email)) != 0:
## CRITICAL TODO: Handle case sensitivity for e-mails ## CRITICAL TODO: Handle case sensitivity for e-mails
return HttpResponse(json.dumps({'success':False, return HttpResponse(json.dumps({'success':False,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment