Skip to content

Commit

Permalink
Restrict new usernames
Browse files Browse the repository at this point in the history
New users may only select usernames following this rules:
* min 3, max 16 characters
* starts with an letter and ends with an letter or number
* may only contain [a-zA-Z0-9_.]

fixes #494
  • Loading branch information
christophmeissner committed Mar 28, 2022
1 parent 31d25ca commit dbc4919
Show file tree
Hide file tree
Showing 34 changed files with 603 additions and 43 deletions.
49 changes: 49 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
from django import forms
from django.core.validators import RegexValidator
from django.utils.text import gettext_lazy as _

from registration.forms import RegistrationFormUniqueEmail

username_first_char_validator = RegexValidator(
r"^[a-zA-Z]", _("Username must start with a letter.")
)
username_validator = RegexValidator(
r"^[a-zA-Z0-9_.]*$",
_('Invalid username. Allowed characters are letters, numbers, "." and "_".'),
)
username_last_char_validator = RegexValidator(
r"[a-zA-Z0-9]$", _("Username must end with a letter or a number.")
)
no_consequtive_dots = RegexValidator(
r"\.\.",
_("Username must not contain consecutive . or _ characters."),
inverse_match=True,
)
no_consequtive_underscores = RegexValidator(
r"__",
_("Username must not contain consecutive . or _ characters."),
inverse_match=True,
)
no_consequtive_funnystuff = RegexValidator(
r"_\.",
_("Username must not contain consecutive . or _ characters."),
inverse_match=True,
)
no_consequtive_funnystuff2 = RegexValidator(
r"\._",
_("Username must not contain consecutive . or _ characters."),
inverse_match=True,
)


class RegistrationForm(RegistrationFormUniqueEmail):

username = forms.CharField(
max_length=16,
min_length=3,
strip=False,
validators=[
username_first_char_validator,
username_validator,
username_last_char_validator,
no_consequtive_dots,
no_consequtive_underscores,
no_consequtive_funnystuff,
no_consequtive_funnystuff2,
],
)

accept_privacy_policy = forms.BooleanField(
required=True, initial=False, label=_("Accept privacy policy")
)
14 changes: 13 additions & 1 deletion locale/ar/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2022-03-15 17:56+0000\n"
"Last-Translator: Christoph Meißner\n"
"Language-Team: Arabic (http://www.transifex.com/coders4help/volunteer-planner/language/ar/)\n"
Expand Down Expand Up @@ -36,6 +36,18 @@ msgstr ""
msgid "Accounts"
msgstr "الحسابات "

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/bg/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2022-03-15 17:56+0000\n"
"Last-Translator: Christoph Meißner\n"
"Language-Team: Bulgarian (http://www.transifex.com/coders4help/volunteer-planner/language/bg/)\n"
Expand Down Expand Up @@ -32,6 +32,18 @@ msgstr ""
msgid "Accounts"
msgstr ""

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2022-03-15 17:56+0000\n"
"Last-Translator: Christoph Meißner\n"
"Language-Team: Czech (http://www.transifex.com/coders4help/volunteer-planner/language/cs/)\n"
Expand Down Expand Up @@ -34,6 +34,18 @@ msgstr "poslední přihlášení"
msgid "Accounts"
msgstr "Účty"

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr "Přijmout zásady ochrany osobních údajů"

Expand Down
14 changes: 13 additions & 1 deletion locale/da/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2017-09-22 15:35+0000\n"
"Last-Translator: Dorian Cantzen <[email protected]>\n"
"Language-Team: Danish (http://www.transifex.com/coders4help/volunteer-planner/language/da/)\n"
Expand Down Expand Up @@ -33,6 +33,18 @@ msgstr ""
msgid "Accounts"
msgstr ""

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2016-11-21 18:24+0000\n"
"Last-Translator: Sönke Klinger <[email protected]>\n"
"Language-Team: German (http://www.transifex.com/coders4help/volunteer-planner/language/de/)\n"
Expand Down Expand Up @@ -47,6 +47,18 @@ msgstr "Letzte Anmeldung"
msgid "Accounts"
msgstr "Benutzerkonten"

msgid "Username must start with a letter."
msgstr "Benutzername muss mit einem Buchstaben anfangen."

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr "Ungültiger Benutzername. Erlaubte Zeichen sind Buchstaben, Ziffern, \".\" and \".\"."

msgid "Username must end with a letter or a number."
msgstr "Benutzername muss mit einem Buchstaben oder einer Ziffer enden."

msgid "Username must not contain consecutive . or _ characters."
msgstr "Benutzername darf keine aufeinanderfolgenden . oder _ enthalten."

msgid "Accept privacy policy"
msgstr "Einwilligung (nach Art 6 Abs 1 Satz 1 a DSGVO)"

Expand Down
14 changes: 13 additions & 1 deletion locale/el/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2016-01-29 08:23+0000\n"
"Last-Translator: Dorian Cantzen <[email protected]>\n"
"Language-Team: Greek (http://www.transifex.com/coders4help/volunteer-planner/language/el/)\n"
Expand Down Expand Up @@ -37,6 +37,18 @@ msgstr ""
msgid "Accounts"
msgstr "Λογαριασμοί"

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2015-10-04 21:53+0000\n"
"Last-Translator: Dorian Cantzen <[email protected]>\n"
"Language-Team: English (http://www.transifex.com/coders4help/volunteer-planner/language/en/)\n"
Expand All @@ -29,6 +29,18 @@ msgstr ""
msgid "Accounts"
msgstr ""

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2016-04-13 17:27+0000\n"
"Last-Translator: Antonio Mireles <[email protected]>\n"
"Language-Team: Spanish (http://www.transifex.com/coders4help/volunteer-planner/language/es/)\n"
Expand Down Expand Up @@ -36,6 +36,18 @@ msgstr ""
msgid "Accounts"
msgstr "Cuentas"

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/es_MX/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2015-09-24 12:23+0000\n"
"Last-Translator: Dorian Cantzen <[email protected]>\n"
"Language-Team: Spanish (Mexico) (http://www.transifex.com/coders4help/volunteer-planner/language/es_MX/)\n"
Expand Down Expand Up @@ -32,6 +32,18 @@ msgstr ""
msgid "Accounts"
msgstr ""

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/fa/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2016-01-29 08:23+0000\n"
"Last-Translator: Dorian Cantzen <[email protected]>\n"
"Language-Team: Persian (http://www.transifex.com/coders4help/volunteer-planner/language/fa/)\n"
Expand Down Expand Up @@ -32,6 +32,18 @@ msgstr ""
msgid "Accounts"
msgstr ""

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2016-12-08 20:50+0000\n"
"Last-Translator: Dolfeus <[email protected]>\n"
"Language-Team: French (http://www.transifex.com/coders4help/volunteer-planner/language/fr/)\n"
Expand Down Expand Up @@ -38,6 +38,18 @@ msgstr ""
msgid "Accounts"
msgstr "Comptes utilisateur"

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
14 changes: 13 additions & 1 deletion locale/hr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: volunteer-planner.org\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-25 11:54+0100\n"
"POT-Creation-Date: 2022-03-25 21:54+0100\n"
"PO-Revision-Date: 2016-01-29 08:23+0000\n"
"Last-Translator: Dorian Cantzen <[email protected]>\n"
"Language-Team: Croatian (http://www.transifex.com/coders4help/volunteer-planner/language/hr/)\n"
Expand Down Expand Up @@ -32,6 +32,18 @@ msgstr ""
msgid "Accounts"
msgstr ""

msgid "Username must start with a letter."
msgstr ""

msgid "Invalid username. Allowed characters are letters, numbers, \".\" and \"_\"."
msgstr ""

msgid "Username must end with a letter or a number."
msgstr ""

msgid "Username must not contain consecutive . or _ characters."
msgstr ""

msgid "Accept privacy policy"
msgstr ""

Expand Down
Loading

0 comments on commit dbc4919

Please sign in to comment.