Permalink
Browse files

Fixes e-mail back-end for account registration. Closes #108

  • Loading branch information...
1 parent 28ceaa1 commit ce5035a0b26e703f55a9f015c752d9aa6c9feabd @ndarville committed Mar 23, 2013
Showing with 14 additions and 6 deletions.
  1. +11 −1 forum/forms.py
  2. +2 −1 forum/views.py
  3. +0 −2 ponyforum/example_local_settings.py
  4. +1 −2 ponyforum/settings.py
View
@@ -35,21 +35,31 @@ class CustomRegistrationForm(RegistrationFormUniqueEmail):
def clean_email(self):
"""Validate that the supplied e-mail address is unique for the
site.
+
+ `strict_email` converts submitted e-mail addresses to ensure
+ that they conform with TO and FROM format required by
+ services like Gmail as explained in
+
+ http://blog.yimingliu.com/2008/11/26/email-servers-and-mail-from-syntax
"""
+ strict_email = '<' + self.cleaned_data['email'] + '>'
+
error_message = "This email address is already in use. \
Please enter a unique one."
if "+" in self.cleaned_data['email']:
raise forms.ValidationError(_(
"Sorry, we currently do not support +filters in e-mail addresses."))
- elif User.objects.filter(email__iexact=self.cleaned_data['email']):
+ elif User.objects.filter(email__iexact=strict_email):
raise forms.ValidationError(_(error_message))
# # If the address is of the type name+filter@example.com
# elif "+" in self.cleaned_data['email'] and User.objects.filter(
# # Search for e-mail that begins with name+, ends with @example.com
# email__startswith=self.cleaned_data['email'].split("+")[0],
# email__endswith='@'+self.cleaned_data['email'].split("@")[1]):
# raise forms.ValidationError(_(error_message))
+ else:
+ return strict_email
def clean(self):
"""Verifiy that the values entered into the two password fields
View
@@ -844,7 +844,8 @@ def custom_register(request, **kwargs):
'site_config_error': site_config_error,
'email_config_error': email_config_error,
'max_username_length':
- User._meta.get_field("username").max_length})
+ User._meta.get_field("username").max_length},
+ form_class=CustomRegistrationForm)
@login_required()
@@ -82,8 +82,6 @@
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
-EMAIL_SUBJECT_PREFIX = '[Pony Forum] ' # Does not work (anymore?)
-DEFAULT_FROM_EMAIL = 'noreply@equestria.pony'
if EMAIL_HOST_USER == "myusername@gmail.com":
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
View
@@ -245,8 +245,7 @@
EMAIL_HOST_PASSWORD = env.get('EMAIL_HOST_PASSWORD', 'mypassword')
EMAIL_PORT = int(env.get('EMAIL_PORT', '587'))
EMAIL_USE_TLS = env.get('EMAIL_USE_TLS', 'True') == 'True'
-# DEFAULT_FROM_EMAIL = env.get('DEFAULT_FROM_EMAIL', 'noreply@equestria.pony')
-# EMAIL_SUBJECT_PREFIX = "" # Doesn't work, optional
+DEFAULT_FROM_EMAIL = '<' + EMAIL_HOST + '>' # Brackets required for Gmail
###
### DJANGO-REGISTRATION

0 comments on commit ce5035a

Please sign in to comment.