diff --git a/seahub/base/accounts.py b/seahub/base/accounts.py index e720045850..ee87d2e9a7 100644 --- a/seahub/base/accounts.py +++ b/seahub/base/accounts.py @@ -1,4 +1,6 @@ # encoding: utf-8 +import re + from django import forms from django.core.mail import send_mail from django.utils import translation @@ -530,9 +532,15 @@ class RegistrationForm(forms.Form): password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False), label=_("Password (again)")) + @classmethod + def allow_register(self, email): + prog = re.compile(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", + re.IGNORECASE) + return False if prog.match(email) is None else True + def clean_email(self): email = self.cleaned_data['email'] - if not is_valid_username(email): + if not self.allow_register(email): raise forms.ValidationError(_("Enter a valid email address.")) emailuser = ccnet_threaded_rpc.get_emailuser(email) diff --git a/tests/seahub/base/test_accounts.py b/tests/seahub/base/test_accounts.py index d89beadde2..842a6e7018 100644 --- a/tests/seahub/base/test_accounts.py +++ b/tests/seahub/base/test_accounts.py @@ -1,5 +1,5 @@ from seahub.test_utils import BaseTestCase -from seahub.base.accounts import User +from seahub.base.accounts import User, RegistrationForm from post_office.models import Email @@ -15,3 +15,38 @@ class UserTest(BaseTestCase): assert len(Email.objects.all()) > 0 # email = Email.objects.all()[0] # print email.html_message + + +class RegistrationFormTest(BaseTestCase): + def setUp(self): + self.valid_emails = [ + 'a@1.com', + 'a.1@1.com', + 'a+.1@1.com-pany', + 'a+-_.1@1.com-pany', + ] + + self.invalid_emails = [ + '"a"@1.com', + '