diff --git a/sahara/db.sqlite3 b/sahara/db.sqlite3 index 3c6d0fb..a9ec1ea 100644 Binary files a/sahara/db.sqlite3 and b/sahara/db.sqlite3 differ diff --git a/sahara/main/__pycache__/admin.cpython-312.pyc b/sahara/main/__pycache__/admin.cpython-312.pyc index 00e14cd..736ac7f 100644 Binary files a/sahara/main/__pycache__/admin.cpython-312.pyc and b/sahara/main/__pycache__/admin.cpython-312.pyc differ diff --git a/sahara/main/__pycache__/models.cpython-312.pyc b/sahara/main/__pycache__/models.cpython-312.pyc index 8ced3f8..49e3c15 100644 Binary files a/sahara/main/__pycache__/models.cpython-312.pyc and b/sahara/main/__pycache__/models.cpython-312.pyc differ diff --git a/sahara/main/__pycache__/views.cpython-312.pyc b/sahara/main/__pycache__/views.cpython-312.pyc index 3454408..8adbc42 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/admin.py b/sahara/main/admin.py index 29298ee..bf461d9 100644 --- a/sahara/main/admin.py +++ b/sahara/main/admin.py @@ -1,8 +1,8 @@ from django.contrib import admin -from .models import BaseUser,Role +from .models import BaseUser # Register your models here. admin.site.register(BaseUser) -admin.site.register(Role) + diff --git a/sahara/main/migrations/0001_initial.py b/sahara/main/migrations/0001_initial.py index 72bd337..c2014a6 100644 --- a/sahara/main/migrations/0001_initial.py +++ b/sahara/main/migrations/0001_initial.py @@ -1,7 +1,7 @@ -# Generated by Django 5.1.4 on 2025-01-11 11:43 +# Generated by Django 5.1.4 on 2025-01-11 12:36 import django.contrib.auth.models -import django.db.models.deletion +import django.contrib.auth.validators import django.utils.timezone from django.db import migrations, models @@ -15,14 +15,6 @@ class Migration(migrations.Migration): ] operations = [ - migrations.CreateModel( - name='Role', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('role', models.CharField(max_length=20)), - ('role_desc', models.TextField()), - ], - ), migrations.CreateModel( name='BaseUser', fields=[ @@ -30,32 +22,32 @@ class Migration(migrations.Migration): ('password', models.CharField(max_length=128, verbose_name='password')), ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), + ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), - ('image', models.ImageField(blank=True, null=True, upload_to='')), + ('image', models.ImageField(blank=True, null=True, upload_to='user_profiles/')), ('bio', models.TextField(blank=True, null=True)), - ('address', models.CharField(blank=True, max_length=50, null=True)), - ('contact_number', models.CharField(blank=True, max_length=15, null=True, unique=True)), - ('email', models.EmailField(max_length=254, unique=True)), - ('citizenship', models.FileField(blank=True, null=True, upload_to='uploads/citizenship')), - ('certificate', models.FileField(blank=True, null=True, upload_to='uploads/certificates')), - ('token', models.CharField(blank=True, max_length=64, null=True)), + ('address', models.TextField(blank=True, null=True)), + ('contact_number', models.CharField(blank=True, max_length=15, null=True)), + ('citizenship', models.CharField(blank=True, max_length=100, null=True)), + ('certificate', models.FileField(blank=True, null=True, upload_to='certificates/')), ('is_verified', models.BooleanField(default=False)), - ('price', models.DecimalField(blank=True, decimal_places=2, max_digits=9999, null=True)), - ('ratings', models.IntegerField(default=1)), + ('price', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)), + ('ratings', models.DecimalField(decimal_places=2, default=0.0, max_digits=3)), + ('role', models.CharField(choices=[('CLIENT', 'CLIENT'), ('ADMIN', 'ADMIN'), ('SERVICE_PROVIDER', 'SERVICE_PROVIDER')], default='CLIENT', max_length=50)), ('member_since', models.DateTimeField(auto_now_add=True)), ('profile_updated', models.DateTimeField(auto_now=True)), + ('token', models.CharField(blank=True, max_length=256, null=True)), ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), - ('role', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='users', to='main.role')), ], options={ - 'verbose_name': 'user', - 'verbose_name_plural': 'users', - 'abstract': False, + 'verbose_name': 'Base User', + 'verbose_name_plural': 'Base Users', }, managers=[ ('objects', django.contrib.auth.models.UserManager()), diff --git a/sahara/main/migrations/__pycache__/0001_initial.cpython-312.pyc b/sahara/main/migrations/__pycache__/0001_initial.cpython-312.pyc index 8ac686c..0a08844 100644 Binary files a/sahara/main/migrations/__pycache__/0001_initial.cpython-312.pyc and b/sahara/main/migrations/__pycache__/0001_initial.cpython-312.pyc differ diff --git a/sahara/main/migrations/__pycache__/0002_alter_baseuser_username.cpython-312.pyc b/sahara/main/migrations/__pycache__/0002_alter_baseuser_username.cpython-312.pyc new file mode 100644 index 0000000..b1485a6 Binary files /dev/null and b/sahara/main/migrations/__pycache__/0002_alter_baseuser_username.cpython-312.pyc differ diff --git a/sahara/main/migrations/__pycache__/0003_alter_baseuser_price.cpython-312.pyc b/sahara/main/migrations/__pycache__/0003_alter_baseuser_price.cpython-312.pyc new file mode 100644 index 0000000..2ad9068 Binary files /dev/null and b/sahara/main/migrations/__pycache__/0003_alter_baseuser_price.cpython-312.pyc differ diff --git a/sahara/main/models.py b/sahara/main/models.py index 9341214..efa7069 100644 --- a/sahara/main/models.py +++ b/sahara/main/models.py @@ -1,43 +1,41 @@ -from django.db import models from django.contrib.auth.models import AbstractUser -from django.dispatch import receiver -from django.db.models.signals import post_save - - - - -class Role(models.Model): - role = models.CharField(max_length=20) - role_desc = models.TextField() - - def __str__(self): - return self.role +from django.db import models class BaseUser(AbstractUser): - username = None - image = models.ImageField(null=True, blank=True) - bio = models.TextField(null=True, blank=True) - address = models.CharField(null=True, blank=True, max_length=50) - contact_number = models.CharField(unique=True, max_length=15, null=True, blank=True) - email = models.EmailField(unique=True) - citizenship = models.FileField(upload_to='uploads/citizenship', null=True, blank=True) - certificate = models.FileField(upload_to='uploads/certificates', blank=True, null=True) - #is_activated = models.BooleanField(default=False) - token = models.CharField(max_length=64,blank=True,null=True) + # Additional fields to extend the default user model + + # Profile-related fields + image = models.ImageField(upload_to='user_profiles/', blank=True, null=True) + bio = models.TextField(blank=True, null=True) + address = models.TextField(blank=True, null=True) + contact_number = models.CharField(max_length=15, blank=True, null=True) + citizenship = models.CharField(max_length=100, blank=True, null=True) + certificate = models.FileField(upload_to='certificates/', blank=True, null=True) + + # Verification and status is_verified = models.BooleanField(default=False) - price = models.DecimalField(max_digits=9999, decimal_places=2, null=True, blank=True) - ratings = models.IntegerField(default=1) - role = models.ForeignKey('Role', on_delete=models.SET_NULL, related_name="users", null=True, blank=True) + + # Financial or business-related fields + price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) + ratings = models.DecimalField(max_digits=3, decimal_places=2, default=0.00) + + # Role and other identifiers + role = models.CharField( + max_length=50, + choices=[('CLIENT', 'CLIENT'), ('ADMIN', 'ADMIN'), ('SERVICE_PROVIDER', 'SERVICE_PROVIDER')], + default='CLIENT' + ) + + # Time-related fields member_since = models.DateTimeField(auto_now_add=True) profile_updated = models.DateTimeField(auto_now=True) - - USERNAME_FIELD = "email" - REQUIRED_FIELDS = ["image", "contact_number", "bio", "address", "citizenship", "certificate", "price", "password"] - + + # Token field for verification or authentication purposes + token = models.CharField(max_length=256, blank=True, null=True) + def __str__(self): - return self.email + return self.username - @receiver(post_save, sender=AbstractUser) - def user_to_inactive(sender, instance, created, update_fields, **kwargs): - if created: - instance.is_active = False + class Meta: + verbose_name = 'Base User' + verbose_name_plural = 'Base Users' diff --git a/sahara/main/utilities.py b/sahara/main/utilities.py index 83705ba..846fc18 100644 --- a/sahara/main/utilities.py +++ b/sahara/main/utilities.py @@ -4,7 +4,7 @@ from django.utils.html import strip_tags from django.conf import settings from django.urls import reverse from django.contrib.sites.shortcuts import get_current_site -from django.contrib.auth.tokens import default_token_generator + def send_welcome_email(user, request): token = 'generated_token_here' diff --git a/sahara/main/views.py b/sahara/main/views.py index 449ef55..94cd1dc 100644 --- a/sahara/main/views.py +++ b/sahara/main/views.py @@ -43,41 +43,13 @@ def send_mail_page(): result = f'Error sending email: {e}' -def send_welcome_email(user, request): - # Generate activation link - user = BaseUser.objects.get(email="user@example.com") # Replace with your user object - token = default_token_generator.make_token(user) - token = 'generated_token_here' # This token will be generated based on your activation logic - activation_link = f"{get_current_site(request).domain}{reverse('account:activate', args=[token])}" - - # Prepare email subject and message - subject = "Welcome to Sahara - Please Activate Your Account" - - # Render the HTML email - html_message = render_to_string('welcome_email.html', { - 'user': user, - 'activation_link': activation_link, - }) - - # Render the plain-text version of the email - plain_message = strip_tags(html_message) - - # Send the email - send_mail( - subject, - plain_message, - settings.DEFAULT_FROM_EMAIL, - [user.email], - html_message=html_message, - ) - - -def activate_account(request, token): +def activate_account(request,token): + return try: # Decode token and retrieve user - user = User.objects.get(email__iexact=user_email_from_token) + user = BaseUser.objects.get(email__iexact="") if user: # Activate user account user.is_active = True