diff --git a/src/postorius/forms.py b/src/postorius/forms.py index b4328d6..b25458e 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -20,7 +20,16 @@ from django.core.validators import validate_email from django.utils.encoding import smart_text from django.utils.translation import ugettext_lazy as _ +from django.contrib.auth.models import User + from postorius.fieldset_forms import FieldsetForm +from postorius.models import AddressConfirmationProfile +from postorius import utils + +try: + from urllib2 import HTTPError +except ImportError: + from urllib.error import HTTPError ACTION_CHOICES = ( @@ -754,16 +763,24 @@ class AddressActivationForm(forms.Form): email = forms.EmailField() - user_email = forms.EmailField(widget=forms.HiddenInput) - def clean(self): - cleaned_data = super(AddressActivationForm, self).clean() - email = cleaned_data.get('email') - user_email = cleaned_data.get('user_email') - if email == user_email: - raise forms.ValidationError(_('Please provide a different email ' - 'address than your own.')) - return cleaned_data + def clean_email(self): + email = self.cleaned_data.get('email') + + # Check if the address belongs to someone else + if User.objects.filter(email=email).exists(): + raise forms.ValidationError(_('This email is in use.' + 'Please choose another or contact the administrator'), + 'error') + + # Check if the email is attached to a user in Mailman + try: + utils.get_client().get_user(email) + raise forms.ValidationError(_('This email already belongs to a user'), 'error') + except HTTPError: + pass + return email + class ChangeSubscriptionForm(forms.Form): email = forms.ChoiceField() diff --git a/src/postorius/migrations/0002_auto_20160209_0635.py b/src/postorius/migrations/0002_auto_20160209_0635.py new file mode 100644 index 0000000..34af0cc --- /dev/null +++ b/src/postorius/migrations/0002_auto_20160209_0635.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('postorius', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='addressconfirmationprofile', + name='created', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/src/postorius/models.py b/src/postorius/models.py index 043c2bc..a974e43 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -257,7 +257,7 @@ """ email = models.EmailField() activation_key = models.CharField(max_length=40) - created = models.DateTimeField() + created = models.DateTimeField(auto_now=True) user = models.ForeignKey(User) objects = AddressConfirmationProfileManager() diff --git a/src/postorius/templates/postorius/menu/user_nav.html b/src/postorius/templates/postorius/menu/user_nav.html index 94054ac..c139547 100644 --- a/src/postorius/templates/postorius/menu/user_nav.html +++ b/src/postorius/templates/postorius/menu/user_nav.html @@ -5,7 +5,6 @@ -