[extensions-web/wip/ne0sight: 3/3] auth: disallow same username and email for registration
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web/wip/ne0sight: 3/3] auth: disallow same username and email for registration
- Date: Mon, 25 Nov 2019 19:58:06 +0000 (UTC)
commit 9945b78b9ff2eabd3f5ed48cd1e19aee64c99b31
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Mon Nov 25 23:57:30 2019 +0400
auth: disallow same username and email for registration
Closes: https://gitlab.gnome.org/Infrastructure/extensions-web/issues/19
po/extensions-web.pot | 6 +++++-
sweettooth/auth/forms.py | 7 +++++++
sweettooth/auth/tests.py | 9 +++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/po/extensions-web.pot b/po/extensions-web.pot
index 7ddf53d..c9f05b3 100644
--- a/po/extensions-web.pot
+++ b/po/extensions-web.pot
@@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: ykonotopov gnome org\n"
-"POT-Creation-Date: 2019-11-25 19:54+0000\n"
+"POT-Creation-Date: 2019-11-25 19:56+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
@@ -34,6 +34,10 @@ msgstr ""
msgid "Email"
msgstr ""
+#: sweettooth/auth/forms.py:56 extensions-web-domain-django:1
+msgid "You should not use email as username"
+msgstr ""
+
#: sweettooth/auth/templates/registration/login.html:23
#: sweettooth/auth/templates/registration/login_popup_form.html:14
#: extensions-web-domain-django:1
diff --git a/sweettooth/auth/forms.py b/sweettooth/auth/forms.py
index af71887..c92148c 100644
--- a/sweettooth/auth/forms.py
+++ b/sweettooth/auth/forms.py
@@ -49,6 +49,13 @@ class RegistrationForm(RegistrationFormCaseInsensitive, RegistrationFormUniqueEm
email = forms.EmailField(widget=forms.TextInput(attrs=dict(maxlength=75)),
label=_(u'Email'))
+ def clean(self):
+ cleaned_data = super().clean()
+
+ if cleaned_data.get('username') == cleaned_data.get('email'):
+ raise forms.ValidationError(_("You should not use email as username"))
+
+ return cleaned_data
class AutoFocusRegistrationForm(AutoFocusForm, RegistrationForm):
pass
diff --git a/sweettooth/auth/tests.py b/sweettooth/auth/tests.py
index c1944f7..270951b 100644
--- a/sweettooth/auth/tests.py
+++ b/sweettooth/auth/tests.py
@@ -75,6 +75,15 @@ class AuthTests(RegistrationDataTest):
password=self.valid_data['password1']))
class RegistrationTests(RegistrationDataTest):
+ def test_username_email(self):
+ form = RegistrationForm(data=self.valid_data)
+ self.assertTrue(form.is_valid())
+
+ data = self.valid_data.copy()
+ data[User.USERNAME_FIELD] = data['email']
+ form = RegistrationForm(data=data)
+ self.assertFalse(form.is_valid())
+
def test_username_case(self):
data = self.valid_data.copy()
data[User.USERNAME_FIELD] = self.registration_data[User.USERNAME_FIELD].swapcase()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]