mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
Fix invalid email in register issue, https://github.com/haiwen/seafile/issues/1672
This commit is contained in:
@@ -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)
|
||||
|
@@ -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',
|
||||
'<script>@1.com',
|
||||
'//@1.com',
|
||||
'a+.-{}?1@1.com',
|
||||
'a+.-()1@1.com',
|
||||
]
|
||||
|
||||
self.form_class = RegistrationForm
|
||||
|
||||
def test_allow_register(self):
|
||||
for e in self.valid_emails:
|
||||
assert self.form_class.allow_register(e) is True
|
||||
|
||||
for e in self.invalid_emails:
|
||||
assert self.form_class.allow_register(e) is False
|
||||
|
||||
def test_clean_email(self):
|
||||
form = self.form_class({'email': 'some_random_user@1.com',
|
||||
'password1': '123',
|
||||
'password2': '123',
|
||||
})
|
||||
assert form.is_valid() is True
|
||||
assert form.clean_email() == 'some_random_user@1.com'
|
||||
|
Reference in New Issue
Block a user