Login page moved to forms.py, New warning and ban system, a bunch of other shit.

- Change password page from profile settings has been moved over to forms.py
- Login page has been moved over to forms.py. There is no JavaScript right now, however it is still functional.
-Profile_tools_Form has been altered to remove a few unneeded fields that administrators don't need to mess with.
- warned_reason and warned fields are gone from User_tools_Form and will be removed from models.py at a later point.

- a new ban system has been implemented. While bans are still incomplete and lack capabilities to ban IP addresses as of right now, the groundwork is now here and those features can be added later.
- manage_bans page was added.

- A new warning system has been implemented. If a Warning is created, a notification is created automatically with it.  A warning notification replaces the "new announcement" notification type.
- Warning notifications are larger and stand out compared to normal notifications
- When posting, commenting or messaging someone, a check is performed to make sure you've seen the warning notification.
- manage_warnings page was added. This page will also show you the warning history.

- help_text was added to a bunch of fields.
This commit is contained in:
some weird guy
2023-08-23 16:47:28 -07:00
parent e190d76079
commit ca09f3295b
44 changed files with 652 additions and 543 deletions
+85 -9
View File
@@ -1,6 +1,9 @@
from django import forms
from .models import *
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError
from django.utils.timezone import timedelta
from closedverse import settings
# I do want to move each and every form over to here. Not only will this trivialize making new forms, this will also make it more secure or something.
class CommunitySettingForm(forms.ModelForm):
@@ -20,21 +23,62 @@ class CommunitySettingForm(forms.ModelForm):
'community_icon',
'community_banner'
)
class Settomgs_Change_Password(forms.Form):
Old_Password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'auth-input', 'placeholder': 'Old Password'}))
New_Password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'auth-input', 'placeholder': 'New Password'}))
Confirm_Password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'auth-input', 'placeholder': 'Confirm Password'}))
def clean(self):
cleaned_data = super().clean()
old = cleaned_data.get('Old_Password')
new = cleaned_data.get('New_Password')
confirm = cleaned_data.get('Confirm_Password')
if not old or not new or not confirm:
raise forms.ValidationError('Please fill out all the fields.')
if old == new:
raise forms.ValidationError('The old password and new password can\'t be the same.')
if new != confirm:
raise forms.ValidationError('Passwords do not match.')
try:
validate_password(new)
except forms.ValidationError as error:
raise forms.ValidationError("your password fucking sucks!")
return cleaned_data
class PurgeForm(forms.Form):
purge_posts = forms.BooleanField(required=False, label='Purge all posts', help_text='Purge all posts from this user.')
purge_comments = forms.BooleanField(required=False, label='Purge all comments', help_text='Purge all comments from this user.')
restore_all = forms.BooleanField(required=False, label='Restore purged content', help_text='Restore everything that was purged, this will not apply to posts deleted manually.')
class UserForm(forms.ModelForm):
class LoginForm(forms.Form):
username = forms.CharField(max_length=255, widget=forms.TextInput(attrs={'class': 'auth-input', 'placeholder': 'Username'}))
password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'auth-input', 'placeholder': 'Password'}))
def clean(self):
cleaned_data = super(LoginForm, self).clean()
username = cleaned_data.get('username')
password = cleaned_data.get('password')
user = User.objects.authenticate(username=username, password=password)
if user is None:
raise forms.ValidationError("The user doesn't exist.")
elif user[1] == False:
raise forms.ValidationError("Invalid password.", code='invalid')
elif user[1] == 2:
raise forms.ValidationError("This account's password needs to be reset. Contact an admin or reset by email.", code='required_reset')
elif not user[0].is_active():
raise forms.ValidationError("This account was disabled.", code='disabled')
return cleaned_data
class User_tools_Form(forms.ModelForm):
username = forms.CharField(max_length = 64, required = True, help_text = 'Usernames are used when signing in, so be sure to let this user know if you change this.')
c_tokens = forms.IntegerField(min_value = 0, max_value = 100, required = False, help_text = 'The remaining C-Tokens this user has.')
has_mh = forms.BooleanField(required = False, label='Use Mii', help_text='Don\'t fuck with this please.')
avatar = forms.CharField(required = False, help_text = 'If \"Use Mii\" is turned on, The Mii ID should reside here, otherwise any good old URL will do.')
has_mh = forms.BooleanField(required = False, label='Use Mii', help_text='Turn this on to use Mii Hashes instead of normal profile pictures.')
avatar = forms.CharField(required = False, help_text = 'If \"Use Mii\" is turned on, The Mii Hash should reside here, otherwise any good old URL will do.')
class Meta:
model = User
fields = ['username', 'nickname', 'role', 'c_tokens', 'hide_online', 'active', 'can_invite', 'warned', 'has_mh', 'avatar', 'warned_reason']
fields = ['username', 'nickname', 'role', 'c_tokens', 'hide_online', 'active', 'can_invite', 'has_mh', 'avatar']
def clean_username(self):
username = self.cleaned_data.get('username')
@@ -42,11 +86,43 @@ class UserForm(forms.ModelForm):
raise forms.ValidationError("The username contains invalid characters.")
return username
class ProfileForm(forms.ModelForm):
class Profile_tools_Form(forms.ModelForm):
# applying classes is super weird.
comment = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'textarea'}))
let_freedom = forms.BooleanField(required=False, label='Let this user upload images?', help_text='If you disable this, This user will not be able to post images, videos or make a new account.')
class Meta:
model = Profile
fields = ['comment', 'country', 'whatareyou', 'weblink', 'external', 'let_freedom', 'limit_post', 'cannot_edit', 'pronoun_is', 'id_visibility', 'let_friendrequest', 'yeahs_visibility', 'comments_visibility']
fields = ['comment', 'country', 'whatareyou', 'weblink', 'external', 'let_freedom', 'limit_post', 'cannot_edit']
class Give_warning_form(forms.ModelForm):
reason = forms.CharField(required=True, widget=forms.Textarea(attrs={'class': 'textarea'}))
# Super simple, does not need to be it's own form but whatever.
class Meta:
model = Warning
fields = ['reason']
class Give_Ban_Form(forms.ModelForm):
BAN_OPTIONS = [
(1, '1 Day'),
(2, '2 Days'),
(3, '3 Days'),
(7, '1 Week'),
(14, '2 Weeks'),
(30, '1 Month'),
(60, '2 Months'),
(365, '1 Year'),
(None, 'Forever'),
]
# In the future we can add options for IP bans and shit.
reason = forms.CharField(required=True, widget=forms.Textarea(attrs={'class': 'textarea'}))
expiry_date = forms.ChoiceField(required=False, choices=BAN_OPTIONS, initial=1)
def clean_expiry_date(self):
expiry_choice = self.cleaned_data['expiry_date']
if expiry_choice:
return timezone.now() + timedelta(days=int(expiry_choice))
else:
return timezone.now() + timedelta(days=365.25*100) # same exact thing done in indigo.
class Meta:
model = Ban
fields = ['reason', 'expiry_date']