diff options
| author | Bobby <[email protected]> | 2023-05-17 20:15:08 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-05-17 20:15:08 -0400 |
| commit | 488b7ee1233aefbb7bb70ee5958676f852139025 (patch) | |
| tree | 0697e181a58c33ff0dc9a4bbcde1e1f0cc1b20d6 /users | |
| parent | dec69b9a6bdd2845d402280ded58fcafa2809c14 (diff) | |
| download | thatcomputerscientist-488b7ee1233aefbb7bb70ee5958676f852139025.tar.xz thatcomputerscientist-488b7ee1233aefbb7bb70ee5958676f852139025.zip | |
Protected usernames + Skippy comes to chat to lonely users + Handle Multiple Chat users
Diffstat (limited to 'users')
| -rw-r--r-- | users/forms.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/users/forms.py b/users/forms.py index 50179abd..8ce104b1 100644 --- a/users/forms.py +++ b/users/forms.py @@ -9,7 +9,7 @@ from .accountFunctions import store_token from .mail_send import send_email from random import choice from blog.context_processors import avatar_list - +import string class RegisterForm(forms.Form): username = forms.CharField(label='Username', max_length=30, min_length=4) email = forms.EmailField(label='Email') @@ -17,6 +17,23 @@ class RegisterForm(forms.Form): password2 = forms.CharField(label='Password (again)', widget=forms.PasswordInput, min_length=8) captcha = forms.CharField(label='Captcha', max_length=6) expected_captcha = None + protected_usernames = [ + 'admin', + 'administrator', + 'root', + 'thatcomputerscientist', + 'skippy', + 'system', + 'test', + 'user', + 'webmaster', + 'www', + 'postmaster', + 'hostmaster', + 'info', + 'support', + ] + allowed_chars = string.ascii_letters + string.digits def __init__(self, *args, **kwargs): if 'expected_captcha' in kwargs: @@ -37,6 +54,11 @@ class RegisterForm(forms.Form): raise forms.ValidationError('Captcha does not match.') if User.objects.filter(username=cleaned_data.get('username')).exists(): raise forms.ValidationError('Username already exists.') + if cleaned_data.get('username').lower() in self.protected_usernames: + raise forms.ValidationError('Username not allowed. Please choose another.') + for char in cleaned_data.get('username'): + if char not in self.allowed_chars: + raise forms.ValidationError('Username contains invalid characters. Only A-Z, a-z, and 0-9 are allowed.') if User.objects.filter(email=cleaned_data.get('email')).exists(): raise forms.ValidationError('Email already exists.') return cleaned_data |
