diff --git a/civicfix/civicfix/__pycache__/settings.cpython-313.pyc b/civicfix/civicfix/__pycache__/settings.cpython-313.pyc index 592f0d4..9100e23 100644 Binary files a/civicfix/civicfix/__pycache__/settings.cpython-313.pyc and b/civicfix/civicfix/__pycache__/settings.cpython-313.pyc differ diff --git a/civicfix/civicfix/settings.py b/civicfix/civicfix/settings.py index ba0425d..b8c4d3f 100644 --- a/civicfix/civicfix/settings.py +++ b/civicfix/civicfix/settings.py @@ -29,6 +29,8 @@ INSTALLED_APPS = [ 'core', ] +AUTH_USER_MODEL = 'core.User' + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -113,3 +115,6 @@ STATIC_URL = 'static/' # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +LOGIN_REDIRECT_URL = 'home' +LOGOUT_REDIRECT_URL = 'home' diff --git a/civicfix/core/__pycache__/admin.cpython-313.pyc b/civicfix/core/__pycache__/admin.cpython-313.pyc index 2b39130..b71af22 100644 Binary files a/civicfix/core/__pycache__/admin.cpython-313.pyc and b/civicfix/core/__pycache__/admin.cpython-313.pyc differ diff --git a/civicfix/core/__pycache__/apps.cpython-313.pyc b/civicfix/core/__pycache__/apps.cpython-313.pyc index 41d6f5a..bb8d376 100644 Binary files a/civicfix/core/__pycache__/apps.cpython-313.pyc and b/civicfix/core/__pycache__/apps.cpython-313.pyc differ diff --git a/civicfix/core/__pycache__/forms.cpython-313.pyc b/civicfix/core/__pycache__/forms.cpython-313.pyc new file mode 100644 index 0000000..630c814 Binary files /dev/null and b/civicfix/core/__pycache__/forms.cpython-313.pyc differ diff --git a/civicfix/core/__pycache__/models.cpython-313.pyc b/civicfix/core/__pycache__/models.cpython-313.pyc index 5b9a7dd..8c0e36e 100644 Binary files a/civicfix/core/__pycache__/models.cpython-313.pyc and b/civicfix/core/__pycache__/models.cpython-313.pyc differ diff --git a/civicfix/core/__pycache__/urls.cpython-313.pyc b/civicfix/core/__pycache__/urls.cpython-313.pyc index 56eeed5..62119fb 100644 Binary files a/civicfix/core/__pycache__/urls.cpython-313.pyc and b/civicfix/core/__pycache__/urls.cpython-313.pyc differ diff --git a/civicfix/core/__pycache__/views.cpython-313.pyc b/civicfix/core/__pycache__/views.cpython-313.pyc index 3a31bf9..dfb2473 100644 Binary files a/civicfix/core/__pycache__/views.cpython-313.pyc and b/civicfix/core/__pycache__/views.cpython-313.pyc differ diff --git a/civicfix/core/admin.py b/civicfix/core/admin.py index 8c38f3f..5366034 100644 --- a/civicfix/core/admin.py +++ b/civicfix/core/admin.py @@ -1,3 +1,25 @@ from django.contrib import admin +from django.contrib.auth.admin import UserAdmin +from .models import User -# Register your models here. +# Unregister default User model if it's registered +# admin.site.unregister(User) # Only needed if User was previously registered + +@admin.register(User) +class CustomUserAdmin(UserAdmin): + list_display = ('username', 'email', 'phone', 'is_citizen', 'is_staff') + list_filter = ('is_citizen', 'is_moderator', 'is_resolver', 'is_staff') + fieldsets = ( + (None, {'fields': ('username', 'password')}), + ('Personal info', {'fields': ('first_name', 'last_name', 'email', 'phone')}), + ('Permissions', { + 'fields': ('is_active', 'is_staff', 'is_superuser', 'is_citizen', 'is_moderator', 'is_resolver', 'groups', 'user_permissions'), + }), + ('Important dates', {'fields': ('last_login', 'date_joined')}), + ) + add_fieldsets = ( + (None, { + 'classes': ('wide',), + 'fields': ('username', 'email', 'phone', 'password1', 'password2'), + }), + ) \ No newline at end of file diff --git a/civicfix/core/apps.py b/civicfix/core/apps.py index 8115ae6..db03dda 100644 --- a/civicfix/core/apps.py +++ b/civicfix/core/apps.py @@ -1,6 +1,9 @@ from django.apps import AppConfig - class CoreConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'core' + + def ready(self): + # Import signals or other startup code here if needed + pass \ No newline at end of file diff --git a/civicfix/core/forms.py b/civicfix/core/forms.py new file mode 100644 index 0000000..f41ee0a --- /dev/null +++ b/civicfix/core/forms.py @@ -0,0 +1,21 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm +from .models import User + +class CitizenRegistrationForm(UserCreationForm): + email = forms.EmailField(required=True) + phone = forms.CharField(max_length=15, required=False) + + class Meta: + model = User + fields = ['username', 'email', 'phone', 'password1', 'password2'] + + def save(self, commit=True): + user = super().save(commit=False) + user.email = self.cleaned_data['email'] + user.phone = self.cleaned_data['phone'] + user.is_citizen = True + + if commit: + user.save() + return user \ No newline at end of file diff --git a/civicfix/core/migrations/0001_initial.py b/civicfix/core/migrations/0001_initial.py new file mode 100644 index 0000000..7d6412f --- /dev/null +++ b/civicfix/core/migrations/0001_initial.py @@ -0,0 +1,48 @@ +# Generated by Django 5.2.5 on 2025-08-18 15:07 + +import django.contrib.auth.models +import django.contrib.auth.validators +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('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')), + ('is_citizen', models.BooleanField(default=False)), + ('is_moderator', models.BooleanField(default=False)), + ('is_resolver', models.BooleanField(default=False)), + ('phone', models.CharField(blank=True, max_length=15, 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')), + ], + options={ + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + 'abstract': False, + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/civicfix/core/migrations/__init__.py b/civicfix/core/migrations/__init__.py index e69de29..8d1c8b6 100644 --- a/civicfix/core/migrations/__init__.py +++ b/civicfix/core/migrations/__init__.py @@ -0,0 +1 @@ + diff --git a/civicfix/core/migrations/__pycache__/0001_initial.cpython-313.pyc b/civicfix/core/migrations/__pycache__/0001_initial.cpython-313.pyc new file mode 100644 index 0000000..4682d1c Binary files /dev/null and b/civicfix/core/migrations/__pycache__/0001_initial.cpython-313.pyc differ diff --git a/civicfix/core/migrations/__pycache__/__init__.cpython-313.pyc b/civicfix/core/migrations/__pycache__/__init__.cpython-313.pyc index e259cd5..b8e3899 100644 Binary files a/civicfix/core/migrations/__pycache__/__init__.cpython-313.pyc and b/civicfix/core/migrations/__pycache__/__init__.cpython-313.pyc differ diff --git a/civicfix/core/models.py b/civicfix/core/models.py index 71a8362..607962c 100644 --- a/civicfix/core/models.py +++ b/civicfix/core/models.py @@ -1,3 +1,12 @@ from django.db import models +from django.contrib.auth.models import AbstractUser +from django.urls import reverse -# Create your models here. +class User(AbstractUser): + is_citizen = models.BooleanField(default=False) + is_moderator = models.BooleanField(default=False) + is_resolver = models.BooleanField(default=False) + phone = models.CharField(max_length=15, blank=True, null=True) + + def get_absolute_url(self): + return reverse('home') \ No newline at end of file diff --git a/civicfix/core/templates/core/register.html b/civicfix/core/templates/core/register.html new file mode 100644 index 0000000..56798e5 --- /dev/null +++ b/civicfix/core/templates/core/register.html @@ -0,0 +1,88 @@ +{% extends "core/base.html" %} + +{% block title %}Register as Citizen{% endblock %} + +{% block content %} +
+
+
+
+
+

Create Citizen Account

+
+ {% csrf_token %} + + {% if form.errors %} +
+ Error! Please correct the following: +
    + {% for field, errors in form.errors.items %} + {% for error in errors %} +
  • {{ error }}
  • + {% endfor %} + {% endfor %} +
+
+ {% endif %} + +
+ + {{ form.username }} + Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. +
+ +
+ + {{ form.email }} +
+ +
+ + {{ form.phone }} +
+ +
+ + {{ form.password1 }} + +
    +
  • Your password can't be too similar to your other personal information.
  • +
  • Your password must contain at least 8 characters.
  • +
  • Your password can't be a commonly used password.
  • +
  • Your password can't be entirely numeric.
  • +
+
+
+ +
+ + {{ form.password2 }} + Enter the same password as before, for verification. +
+ +
+ +
+
+ +
+ +

+ Already have an account? Login here +

+
+
+
+
+
+{% endblock %} + +{% block extra_js %} + +{% endblock %} \ No newline at end of file diff --git a/civicfix/core/urls.py b/civicfix/core/urls.py index 0d4ddcf..0dcea45 100644 --- a/civicfix/core/urls.py +++ b/civicfix/core/urls.py @@ -1,6 +1,10 @@ from django.urls import path +from django.contrib.auth import views as auth_views from . import views urlpatterns = [ path('', views.home, name='home'), + path('register/', views.register, name='register'), + path('login/', auth_views.LoginView.as_view(template_name='core/login.html'), name='login'), + path('logout/', auth_views.LogoutView.as_view(), name='logout'), ] \ No newline at end of file diff --git a/civicfix/core/views.py b/civicfix/core/views.py index 25729de..58ab75a 100644 --- a/civicfix/core/views.py +++ b/civicfix/core/views.py @@ -1,4 +1,17 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect +from django.contrib.auth import login +from .forms import CitizenRegistrationForm def home(request): - return render(request, 'core/index.html') \ No newline at end of file + return render(request, 'core/index.html') + +def register(request): + if request.method == 'POST': + form = CitizenRegistrationForm(request.POST) + if form.is_valid(): + user = form.save() + login(request, user) + return redirect('home') + else: + form = CitizenRegistrationForm() + return render(request, 'core/register.html', {'form': form}) \ No newline at end of file diff --git a/civicfix/db.sqlite3 b/civicfix/db.sqlite3 deleted file mode 100644 index ae6669a..0000000 Binary files a/civicfix/db.sqlite3 and /dev/null differ