add validators module with a first email validator
This commit is contained in:
parent
1c9f0a4107
commit
da64050c63
|
@ -7,8 +7,8 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: Authentic\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2014-04-09 17:07+0200\n"
|
||||
"PO-Revision-Date: 2014-04-09 17:08+0200\n"
|
||||
"POT-Creation-Date: 2014-04-23 17:18+0200\n"
|
||||
"PO-Revision-Date: 2014-04-23 17:19+0200\n"
|
||||
"Last-Translator: Mikaël Ates <mates@entrouvert.com>\n"
|
||||
"Language-Team: None\n"
|
||||
"Language: fr\n"
|
||||
|
@ -420,6 +420,22 @@ msgstr "valeur d'un attribut"
|
|||
msgid "attribute values"
|
||||
msgstr "valeurs des attributs"
|
||||
|
||||
#: validators.py:19 validators.py:48
|
||||
msgid "Enter a valid email address."
|
||||
msgstr "Entrez une adresse de courriel valide."
|
||||
|
||||
#: validators.py:34
|
||||
msgid "Invalid email address."
|
||||
msgstr "Adresse de courriel invalide."
|
||||
|
||||
#: validators.py:41
|
||||
msgid "Nonexistent domain."
|
||||
msgstr "Domaine inexistant."
|
||||
|
||||
#: validators.py:43
|
||||
msgid "Nonexistent email address."
|
||||
msgstr "Adresse de courriel inexistante."
|
||||
|
||||
#: views.py:174
|
||||
msgid ""
|
||||
"Your request for changing your email is received. An email of validation was "
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import smtplib
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.validators import EmailValidator, email_re
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
import dns.resolver
|
||||
|
||||
# copied from http://www.djangotips.com/real-email-validation
|
||||
class EmailValidator(EmailValidator):
|
||||
|
||||
def __call__(self, value):
|
||||
super(EmailValidator, self).__call__(value)
|
||||
try:
|
||||
hostname = value.split('@')[-1]
|
||||
except KeyError:
|
||||
raise ValidationError(_('Enter a valid email address.'))
|
||||
|
||||
try:
|
||||
for server in [ str(r.exchange).rstrip('.') \
|
||||
for r \
|
||||
in dns.resolver.query(hostname, 'MX') ]:
|
||||
try:
|
||||
smtp = smtplib.SMTP()
|
||||
smtp.connect(server)
|
||||
status = smtp.helo()
|
||||
if status[0] != 250:
|
||||
continue
|
||||
smtp.mail('')
|
||||
status = smtp.rcpt(value)
|
||||
if status[0] != 250:
|
||||
raise ValidationError(_('Invalid email address.'))
|
||||
break
|
||||
except smtplib.SMTPServerDisconnected:
|
||||
break
|
||||
except smtplib.SMTPConnectError:
|
||||
continue
|
||||
except dns.resolver.NXDOMAIN:
|
||||
raise ValidationError(_('Nonexistent domain.'))
|
||||
except dns.resolver.NoAnswer:
|
||||
raise ValidationError(_('Nonexistent email address.'))
|
||||
|
||||
|
||||
validate_email = EmailValidator(
|
||||
email_re,
|
||||
_('Enter a valid email address.'),
|
||||
'invalid'
|
||||
)
|
|
@ -7,3 +7,4 @@ django-debug-toolbar<1.0.0
|
|||
--allow-external django-admin-tools
|
||||
--allow-unverified django-admin-tools
|
||||
django-admin-tools>=0.5.1
|
||||
dnspython
|
||||
|
|
Loading…
Reference in New Issue