├── accounts
├── models.py
├── __init__.py
├── migrations
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-313.pyc
│ │ ├── 0001_initial.cpython-313.pyc
│ │ └── 0002_delete_user.cpython-313.pyc
│ ├── 0002_delete_user.py
│ └── 0001_initial.py
├── admin.py
├── tests.py
├── __pycache__
│ ├── admin.cpython-313.pyc
│ ├── apps.cpython-313.pyc
│ ├── urls.cpython-313.pyc
│ ├── views.cpython-313.pyc
│ ├── models.cpython-313.pyc
│ ├── __init__.cpython-313.pyc
│ └── serializers.cpython-313.pyc
├── apps.py
├── urls.py
├── templates
│ ├── dashboard.html
│ └── accounts
│ │ └── register.html
├── serializers.py
└── views.py
├── hazratali
├── __init__.py
├── __pycache__
│ ├── urls.cpython-313.pyc
│ ├── wsgi.cpython-313.pyc
│ ├── __init__.cpython-313.pyc
│ └── settings.cpython-313.pyc
├── urls.py
├── asgi.py
├── wsgi.py
└── settings.py
├── manage.py
└── templates
├── base.html
├── index.html
└── dashboard.html
/accounts/models.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/accounts/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/hazratali/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/accounts/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/accounts/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/accounts/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/accounts/__pycache__/admin.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/__pycache__/admin.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/__pycache__/apps.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/__pycache__/apps.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/__pycache__/urls.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/__pycache__/urls.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/__pycache__/views.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/__pycache__/views.cpython-313.pyc
--------------------------------------------------------------------------------
/hazratali/__pycache__/urls.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/hazratali/__pycache__/urls.cpython-313.pyc
--------------------------------------------------------------------------------
/hazratali/__pycache__/wsgi.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/hazratali/__pycache__/wsgi.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/__pycache__/models.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/__pycache__/models.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/__pycache__/__init__.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/__pycache__/__init__.cpython-313.pyc
--------------------------------------------------------------------------------
/hazratali/__pycache__/__init__.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/hazratali/__pycache__/__init__.cpython-313.pyc
--------------------------------------------------------------------------------
/hazratali/__pycache__/settings.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/hazratali/__pycache__/settings.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/__pycache__/serializers.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/__pycache__/serializers.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/migrations/__pycache__/__init__.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/migrations/__pycache__/__init__.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/migrations/__pycache__/0001_initial.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/migrations/__pycache__/0001_initial.cpython-313.pyc
--------------------------------------------------------------------------------
/accounts/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 | # apps
3 |
4 | class AccountsConfig(AppConfig):
5 | default_auto_field = 'django.db.models.BigAutoField'
6 | name = 'accounts'
7 |
--------------------------------------------------------------------------------
/accounts/migrations/__pycache__/0002_delete_user.cpython-313.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hazrat-Ali9/Hazrat-Ali-Assessment/HEAD/accounts/migrations/__pycache__/0002_delete_user.cpython-313.pyc
--------------------------------------------------------------------------------
/hazratali/urls.py:
--------------------------------------------------------------------------------
1 | # Urls py
2 | from django.contrib import admin
3 | from django.urls import path,include
4 |
5 | urlpatterns = [
6 | path('admin/', admin.site.urls),
7 | path('',include('accounts.urls'))
8 | ]
9 |
--------------------------------------------------------------------------------
/accounts/migrations/0002_delete_user.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 5.1.5 on 2025-08-09 19:01
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('accounts', '0001_initial'),
10 | ]
11 |
12 | operations = [
13 | migrations.DeleteModel(
14 | name='User',
15 | ),
16 | ]
17 |
--------------------------------------------------------------------------------
/hazratali/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for hazratali project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hazratali.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/hazratali/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for hazratali project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hazratali.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/accounts/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from .views import RegisterApiView,Register,LoginApiView,Login,Dashboard,Logout,UserDetailAPIView
3 |
4 | urlpatterns = [
5 | path('api/register/', RegisterApiView.as_view(), name='user-register'),
6 | path('register/',Register,name='register'),
7 | path('api/login/', LoginApiView.as_view(), name='user-login'),
8 | path('',Login,name='login'),
9 | path('logout/', Logout, name='logout'),
10 | path('dashboard/', Dashboard, name='dashboard'),
11 | path('api/user/', UserDetailAPIView.as_view(), name='user_detail'),
12 | ]
13 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hazratali.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/accounts/templates/dashboard.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% block content %}
3 |
4 |
5 |
Welcome to Your Dashboard
6 |
7 |
8 |
9 | First Name:
10 | {{ user.first_name }}
11 |
12 |
13 | Last Name:
14 | {{ user.last_name }}
15 |
16 |
17 | Email:
18 | {{ user.email }}
19 |
20 |
21 |
22 |
27 |
28 |
29 | {% endblock %}
--------------------------------------------------------------------------------
/accounts/serializers.py:
--------------------------------------------------------------------------------
1 | from rest_framework import serializers
2 | from django.contrib.auth.models import User
3 | from django.contrib.auth import authenticate
4 |
5 | class RegisterSerializer(serializers.ModelSerializer):
6 | password = serializers.CharField(write_only=True, min_length=8)
7 |
8 | class Meta:
9 | model = User
10 | fields = ['first_name', 'last_name', 'username', 'email', 'password']
11 |
12 | def create(self, validated_data):
13 | first_name = validated_data.pop('first_name', '')
14 | last_name = validated_data.pop('last_name', '')
15 |
16 | user = User.objects.create_user(
17 | username=validated_data['username'],
18 | email=validated_data.get('email'),
19 | password=validated_data['password']
20 | )
21 | user.first_name = first_name
22 | user.last_name = last_name
23 | user.save()
24 | return user
25 |
26 |
27 | class LoginSerializer(serializers.Serializer):
28 | email = serializers.EmailField()
29 | password = serializers.CharField(write_only=True)
30 |
31 | def validate(self, data):
32 | email = data.get('email')
33 | password = data.get('password')
34 |
35 | if email and password:
36 | try:
37 | user_obj = User.objects.get(email=email)
38 | except User.DoesNotExist:
39 | raise serializers.ValidationError('Invalid email or password')
40 |
41 | user = authenticate(username=user_obj.username, password=password)
42 | if not user:
43 | raise serializers.ValidationError('Invalid email or password')
44 |
45 | data['user'] = user
46 | return data
47 |
48 | else:
49 | raise serializers.ValidationError('Must provide email and password')
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/accounts/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 5.1.5 on 2025-08-09 18:18
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = [
11 | ('auth', '0012_alter_user_first_name_max_length'),
12 | ]
13 |
14 | operations = [
15 | migrations.CreateModel(
16 | name='User',
17 | fields=[
18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19 | ('password', models.CharField(max_length=128, verbose_name='password')),
20 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
21 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
22 | ('email', models.EmailField(max_length=254, unique=True)),
23 | ('first_name', models.CharField(max_length=100)),
24 | ('last_name', models.CharField(max_length=100)),
25 | ('is_active', models.BooleanField(default=True)),
26 | ('is_staff', models.BooleanField(default=False)),
27 | ('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')),
28 | ('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')),
29 | ],
30 | options={
31 | 'abstract': False,
32 | },
33 | ),
34 | ]
35 |
--------------------------------------------------------------------------------
/accounts/views.py:
--------------------------------------------------------------------------------
1 | from rest_framework import generics,status
2 | from rest_framework.views import APIView
3 | from .serializers import RegisterSerializer,LoginSerializer
4 | from rest_framework.permissions import IsAuthenticated
5 | from django.contrib.auth.models import User
6 | from django.contrib.auth import logout
7 | from django.shortcuts import render, redirect
8 | from rest_framework.authtoken.models import Token
9 | from rest_framework.response import Response
10 |
11 | class RegisterApiView(generics.CreateAPIView):
12 | queryset = User.objects.all()
13 | serializer_class = RegisterSerializer
14 |
15 | def create(self, request, *args, **kwargs):
16 | response = super().create(request, *args, **kwargs)
17 | user = User.objects.get(username=response.data['username'])
18 | token, created = Token.objects.get_or_create(user=user)
19 | return Response({
20 | 'token': token.key,
21 | 'username': user.username,
22 | 'email': user.email,
23 | 'fullname': f"{user.first_name} {user.last_name}".strip()
24 | }, status=status.HTTP_201_CREATED)
25 | def Register(request):
26 | return render(request,'accounts/register.html')
27 |
28 | class LoginApiView(generics.GenericAPIView):
29 | serializer_class = LoginSerializer
30 |
31 | def post(self, request, *args, **kwargs):
32 | serializer = self.get_serializer(data=request.data)
33 | serializer.is_valid(raise_exception=True)
34 | user = serializer.validated_data['user']
35 | token, created = Token.objects.get_or_create(user=user)
36 | return Response({'token': token.key, 'username': user.username, 'email': user.email}, status=status.HTTP_200_OK)
37 |
38 | def Login(request):
39 | return render(request,'index.html')
40 |
41 | def Logout(request):
42 | logout(request)
43 | return redirect('login')
44 |
45 | class UserDetailAPIView(APIView):
46 | permission_classes = [IsAuthenticated]
47 |
48 | def get(self, request):
49 | user = request.user
50 | fullname = f"{user.first_name} {user.last_name}".strip()
51 | return Response({
52 | 'fullname': fullname,
53 | 'username': user.username,
54 | 'email': user.email,
55 | })
56 |
57 | def Dashboard(request):
58 | return render(request, 'dashboard.html', {'user': request.user})
59 |
--------------------------------------------------------------------------------
/templates/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Task
7 |
8 |
41 |
92 |
93 |
94 |
95 | {% block content %}
96 |
97 | {% endblock %}
98 |
99 |
100 |
--------------------------------------------------------------------------------
/hazratali/settings.py:
--------------------------------------------------------------------------------
1 |
2 |
3 | from pathlib import Path
4 |
5 |
6 | BASE_DIR = Path(__file__).resolve().parent.parent
7 |
8 |
9 | SECRET_KEY = 'django-insecure-xhmw7+&n0*x0=ir)p*t@o+vjk+cv#3%fr^mri+l4w+vri+93*g'
10 |
11 | DEBUG = True
12 |
13 | ALLOWED_HOSTS = []
14 |
15 |
16 | # Application definition
17 |
18 | INSTALLED_APPS = [
19 | 'django.contrib.admin',
20 | 'django.contrib.auth',
21 | 'django.contrib.contenttypes',
22 | 'django.contrib.sessions',
23 | 'django.contrib.messages',
24 | 'django.contrib.staticfiles',
25 | 'rest_framework',
26 | 'rest_framework.authtoken',
27 | 'accounts'
28 | ]
29 |
30 |
31 | MIDDLEWARE = [
32 | 'django.middleware.security.SecurityMiddleware',
33 | 'django.contrib.sessions.middleware.SessionMiddleware',
34 | 'django.middleware.common.CommonMiddleware',
35 | 'django.middleware.csrf.CsrfViewMiddleware',
36 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
37 | 'django.contrib.messages.middleware.MessageMiddleware',
38 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
39 | ]
40 |
41 | ROOT_URLCONF = 'hazratali.urls'
42 |
43 | TEMPLATES = [
44 | {
45 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
46 | 'DIRS': [BASE_DIR/'templates'],
47 | 'APP_DIRS': True,
48 | 'OPTIONS': {
49 | 'context_processors': [
50 | 'django.template.context_processors.debug',
51 | 'django.template.context_processors.request',
52 | 'django.contrib.auth.context_processors.auth',
53 | 'django.contrib.messages.context_processors.messages',
54 | ],
55 | },
56 | },
57 | ]
58 |
59 | WSGI_APPLICATION = 'hazratali.wsgi.application'
60 |
61 | REST_FRAMEWORK = {
62 | 'DEFAULT_AUTHENTICATION_CLASSES': (
63 | 'rest_framework.authentication.TokenAuthentication',
64 | ),
65 | 'DEFAULT_PERMISSION_CLASSES': [],
66 | }
67 |
68 | LOGIN_URL = '/login/'
69 | LOGIN_REDIRECT_URL = 'dashboard'
70 | LOGOUT_REDIRECT_URL = '/'
71 |
72 | DATABASES = {
73 | 'default': {
74 | 'ENGINE': 'django.db.backends.mysql',
75 | 'NAME': 'auth',
76 | 'USER': 'root',
77 | 'PASSWORD': '',
78 | 'HOST': '127.0.0.1',
79 | 'PORT': '3306',
80 | 'OPTIONS': {
81 | 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
82 | }
83 | }
84 | }
85 |
86 |
87 | AUTH_PASSWORD_VALIDATORS = [
88 | {
89 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
90 | },
91 | {
92 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
93 | },
94 | {
95 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
96 | },
97 | {
98 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
99 | },
100 | ]
101 |
102 |
103 | # Internationalization
104 | # https://docs.djangoproject.com/en/5.1/topics/i18n/
105 |
106 | LANGUAGE_CODE = 'en-us'
107 |
108 | TIME_ZONE = 'UTC'
109 |
110 | USE_I18N = True
111 |
112 | USE_TZ = True
113 |
114 |
115 | # Static files (CSS, JavaScript, Images)
116 | # https://docs.djangoproject.com/en/5.1/howto/static-files/
117 |
118 | STATIC_URL = 'static/'
119 |
120 | # Default primary key field type
121 | # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
122 |
123 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
124 |
--------------------------------------------------------------------------------
/templates/index.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %} {% block content %}
2 |
3 |
4 |
5 |
6 |
7 |
Create Account
8 |
9 |
10 |
11 |
41 |
Don't Have a Account ?
Register Now
42 |
43 |
44 |
85 |
86 |
87 |
88 | {% endblock %}
--------------------------------------------------------------------------------
/accounts/templates/accounts/register.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %} {% block content %}
2 |
3 |
4 |
5 |
6 |
7 |
Create Account
8 |
9 |
10 |
11 |
75 |
Already have an account?
Sign In
76 |
77 |
78 |
79 |
131 |
132 |
133 | {% endblock %}
134 |
--------------------------------------------------------------------------------
/templates/dashboard.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% block content %}
3 |
4 |
5 |
6 |
7 |
8 |
9 |
17 |
Loading...
18 |
Loading account...
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
32 |
33 |
FULL NAME
34 |
Loading...
35 |
36 |
37 |
38 |
39 |
44 |
45 |
EMAIL
46 |
Loading...
47 |
48 |
49 |
50 |
51 |
56 |
57 |
USERNAME
58 |
@loading
59 |
60 |
61 |
62 |
63 |
64 |
65 |
68 |
Logout
69 |
70 |
71 |
72 |
73 |
130 |
131 |
132 | {% endblock %}
--------------------------------------------------------------------------------