diff --git a/sahara/db.sqlite3 b/sahara/db.sqlite3 index 4a9c6a5..27c2ebd 100644 Binary files a/sahara/db.sqlite3 and b/sahara/db.sqlite3 differ diff --git a/sahara/main/__pycache__/forms.cpython-312.pyc b/sahara/main/__pycache__/forms.cpython-312.pyc index 9e091ac..801719f 100644 Binary files a/sahara/main/__pycache__/forms.cpython-312.pyc and b/sahara/main/__pycache__/forms.cpython-312.pyc differ diff --git a/sahara/main/__pycache__/views.cpython-312.pyc b/sahara/main/__pycache__/views.cpython-312.pyc index 0b69e7e..d1a1e12 100644 Binary files a/sahara/main/__pycache__/views.cpython-312.pyc and b/sahara/main/__pycache__/views.cpython-312.pyc differ diff --git a/sahara/main/forms.py b/sahara/main/forms.py index acce591..bbd69ca 100644 --- a/sahara/main/forms.py +++ b/sahara/main/forms.py @@ -1,12 +1,8 @@ from django import forms -from django.contrib.auth.forms import AuthenticationForm +from django.core.exceptions import ValidationError from .models import User -from django import forms -from .models import User, Service - class UserRegistrationForm(forms.ModelForm): - # Password and confirm password fields with custom classes password = forms.CharField( widget=forms.PasswordInput(attrs={ 'class': 'form-control', @@ -22,7 +18,8 @@ class UserRegistrationForm(forms.ModelForm): class Meta: model = User - fields = ['email', 'first_name', 'last_name', 'profile', 'price', 'bio', 'service_offered', 'login_profile'] + fields = ['email', 'first_name', 'last_name', 'profile', 'price', + 'bio', 'service_offered', 'login_profile'] widgets = { 'first_name': forms.TextInput(attrs={ 'class': 'form-control', @@ -43,7 +40,7 @@ class UserRegistrationForm(forms.ModelForm): 'bio': forms.Textarea(attrs={ 'class': 'form-control', 'placeholder': 'Enter your bio', - 'rows': 4, # You can customize the rows and columns as needed + 'rows': 4, }), 'price': forms.NumberInput(attrs={ 'class': 'form-control', @@ -57,22 +54,35 @@ class UserRegistrationForm(forms.ModelForm): }), } + def clean_email(self): + email = self.cleaned_data.get('email') + if User.objects.filter(email=email).exists(): + raise ValidationError('Email is already registered.') + return email + def clean(self): cleaned_data = super().clean() password = cleaned_data.get('password') confirm_password = cleaned_data.get('confirm_password') + + # Password validation + if password: + if len(password) < 8: + raise ValidationError('Password must be at least 8 characters long.') + if not any(char.isdigit() for char in password): + raise ValidationError('Password must contain at least one number.') + if not any(char.isupper() for char in password): + raise ValidationError('Password must contain at least one uppercase letter.') # Check if passwords match - if password != confirm_password: - self.add_error('confirm_password', 'Passwords do not match') + if password and confirm_password and password != confirm_password: + raise ValidationError('Passwords do not match.') return cleaned_data - - def clean(self): - cleaned_data = super().clean() - password = cleaned_data.get('password') - confirm_password = cleaned_data.get('confirm_password') - - if password and confirm_password and password != confirm_password: - raise forms.ValidationError("Passwords do not match.") + def save(self, commit=True): + user = super().save(commit=False) + user.set_password(self.cleaned_data['password']) + if commit: + user.save() + return user diff --git a/sahara/main/templates/main/register.html b/sahara/main/templates/main/register.html index 8cbc3d9..007038f 100644 --- a/sahara/main/templates/main/register.html +++ b/sahara/main/templates/main/register.html @@ -1,133 +1,44 @@ + {% extends 'base.html' %} {% block content %} -
Already have an account? Login here.
+