minor change

This commit is contained in:
2025-08-18 20:23:47 +05:30
parent 916117f3a7
commit 113e1f4417
20 changed files with 219 additions and 5 deletions
+5
View File
@@ -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'
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+23 -1
View File
@@ -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'),
}),
)
+4 -1
View File
@@ -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
+21
View File
@@ -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
+48
View File
@@ -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()),
],
),
]
+1
View File
@@ -0,0 +1 @@
+10 -1
View File
@@ -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')
@@ -0,0 +1,88 @@
{% extends "core/base.html" %}
{% block title %}Register as Citizen{% endblock %}
{% block content %}
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow">
<div class="card-body p-5">
<h2 class="card-title text-center mb-4">Create Citizen Account</h2>
<form method="post">
{% csrf_token %}
{% if form.errors %}
<div class="alert alert-danger">
<strong>Error!</strong> Please correct the following:
<ul>
{% for field, errors in form.errors.items %}
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% endif %}
<div class="mb-3">
<label for="id_username" class="form-label">Username</label>
{{ form.username }}
<small class="text-muted">Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.</small>
</div>
<div class="mb-3">
<label for="id_email" class="form-label">Email</label>
{{ form.email }}
</div>
<div class="mb-3">
<label for="id_phone" class="form-label">Phone (Optional)</label>
{{ form.phone }}
</div>
<div class="mb-3">
<label for="id_password1" class="form-label">Password</label>
{{ form.password1 }}
<small class="text-muted">
<ul>
<li>Your password can't be too similar to your other personal information.</li>
<li>Your password must contain at least 8 characters.</li>
<li>Your password can't be a commonly used password.</li>
<li>Your password can't be entirely numeric.</li>
</ul>
</small>
</div>
<div class="mb-4">
<label for="id_password2" class="form-label">Password Confirmation</label>
{{ form.password2 }}
<small class="text-muted">Enter the same password as before, for verification.</small>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">Register</button>
</div>
</form>
<hr class="my-4">
<p class="text-center text-muted">
Already have an account? <a href="{% url 'login' %}" class="text-decoration-none">Login here</a>
</p>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
// Add Bootstrap classes to form fields
$(document).ready(function() {
$('input').addClass('form-control');
$('input[type="checkbox"]').removeClass('form-control').addClass('form-check-input');
});
</script>
{% endblock %}
+4
View File
@@ -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'),
]
+15 -2
View File
@@ -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')
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})
Binary file not shown.