Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CollegeERP/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
STATIC_URL = '/static/'

LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/accounts/login/'

# Restrict authentication to the fixed credentials backend
AUTHENTICATION_BACKENDS = [
'info.backends.AparnaOnlyBackend',
]

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
Expand Down
31 changes: 31 additions & 0 deletions info/backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.contrib.auth.backends import BaseBackend
from django.contrib.auth import get_user_model


class AparnaOnlyBackend(BaseBackend):
"""
Authenticate only the fixed credentials:
username: 'aparna', password: 'password'.

On success, returns a (possibly auto-created) user instance from the
configured AUTH_USER_MODEL. No other credentials are accepted.
"""

def authenticate(self, request, username=None, password=None, **kwargs):
if username == 'aparna' and password == 'password':
User = get_user_model()
user, _created = User.objects.get_or_create(username='aparna')
# Ensure the user is active for login purposes
if getattr(user, 'is_active', True) is False:
user.is_active = True
user.save(update_fields=['is_active'])
return user
return None

def get_user(self, user_id):
User = get_user_model()
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None

36 changes: 36 additions & 0 deletions info/templates/info/simple_home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dashboard</title>
{% load static %}
<link href="{% static '/info/bootstrap/vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static '/info/bootstrap/vendor/fontawesome-free/css/all.min.css' %}" rel="stylesheet" type="text/css">
<link href="{% static '/info/bootstrap/css/sb-admin.css' %}" rel="stylesheet">
<style>
body { padding-top: 40px; }
</style>
</head>
<body class="bg-light">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow">
<div class="card-header">Welcome</div>
<div class="card-body">
<p class="lead mb-1">You are logged in as <strong>{{ request.user.username }}</strong>.</p>
<p class="text-muted mb-4">This is your main dashboard.</p>
<a class="btn btn-primary" href="{% url 'index' %}">Home</a>
<a class="btn btn-outline-secondary ml-2" href="/accounts/logout">Logout</a>
</div>
</div>
</div>
</div>
</div>
<script src="{% static '/info/bootstrap/vendor/jquery/jquery.min.js' %}"></script>
<script src="{% static '/info/bootstrap/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static '/info/bootstrap/vendor/jquery-easing/jquery.easing.min.js' %}"></script>
</body>
</html>

5 changes: 3 additions & 2 deletions info/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def index(request):
return render(request, 'info/homepage.html')
if request.user.is_superuser:
return render(request, 'info/admin_page.html')
return render(request, 'info/logout.html')
# Default dashboard for generic authenticated users
return render(request, 'info/simple_home.html')


@login_required()
Expand Down Expand Up @@ -422,4 +423,4 @@ def add_student(request):

all_classes = Class.objects.order_by('-id')
context = {'all_classes': all_classes}
return render(request, 'info/add_student.html', context)
return render(request, 'info/add_student.html', context)