Skip to content

Commit d4b30bb

Browse files
authored
Merge pull request #21 from anuket-project/iol-dev
11/19/2024 Deploy
2 parents 134cdf1 + 17d031f commit d4b30bb

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

src/account/middleware.py

+11
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
from django.utils import timezone
1212
from django.utils.deprecation import MiddlewareMixin
13+
from django.shortcuts import render
1314

1415
from account.models import UserProfile
1516

17+
from laas_dashboard.settings import SITE_CONTACT
1618

1719
class TimezoneMiddleware(MiddlewareMixin):
1820
"""
@@ -33,3 +35,12 @@ def process_request(self, request):
3335
timezone.activate(tz)
3436
else:
3537
timezone.deactivate()
38+
39+
class ActiveUserMiddleware(MiddlewareMixin):
40+
def process_request(self, request):
41+
if request.user.is_authenticated and not request.user.is_active and request.path != "/oidc/logout/":
42+
return render(request, "account/account_disabled.html", {
43+
"contact_email": SITE_CONTACT
44+
})
45+
46+
return self.get_response(request)

src/account/views.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from django.shortcuts import render
2424
from booking.lib import attempt_end_booking
2525
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
26-
from laas_dashboard.settings import PROJECT, AUTH_SETTING
26+
from laas_dashboard.settings import PROJECT, AUTH_SETTING, SITE_CONTACT
2727

2828
from account.models import UserProfile
2929
from booking.models import Booking
@@ -119,6 +119,9 @@ def update_user(self, user, claims):
119119
up.save()
120120
return user
121121

122+
def user_can_authenticate(self, user):
123+
return True
124+
122125

123126
class OIDCLoginView(RedirectView):
124127
def get_redirect_url(self, *args, **kwargs):
@@ -253,6 +256,7 @@ def account_dev_login_view(request):
253256
username = request.POST['username']
254257
password = request.POST['password']
255258
user = authenticate(username=username, password=password)
259+
256260
if user is not None:
257261
django_login(request, user)
258262
template_dash = "dashboard/landing.html"

src/laas_dashboard/settings.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@
4646
]
4747

4848
MIDDLEWARE = [
49-
'django.middleware.security.SecurityMiddleware',
49+
"django.middleware.security.SecurityMiddleware",
5050
"whitenoise.middleware.WhiteNoiseMiddleware",
51-
'django.contrib.sessions.middleware.SessionMiddleware',
52-
'django.middleware.common.CommonMiddleware',
53-
'django.middleware.csrf.CsrfViewMiddleware',
54-
'django.contrib.auth.middleware.AuthenticationMiddleware',
55-
'django.contrib.messages.middleware.MessageMiddleware',
56-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
57-
'account.middleware.TimezoneMiddleware',
51+
"django.contrib.sessions.middleware.SessionMiddleware",
52+
"django.middleware.common.CommonMiddleware",
53+
"django.middleware.csrf.CsrfViewMiddleware",
54+
"django.contrib.auth.middleware.AuthenticationMiddleware",
55+
"account.middleware.ActiveUserMiddleware",
56+
"django.contrib.messages.middleware.MessageMiddleware",
57+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
58+
"account.middleware.TimezoneMiddleware"
5859
]
5960

6061
STORAGES = {
@@ -67,7 +68,7 @@
6768
}
6869

6970
# AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend', 'account.views.MyOIDCAB']
70-
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
71+
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.AllowAllUsersModelBackend']
7172

7273
AUTH_SETTING = os.environ.get('AUTH_SETTING')
7374

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "base.html" %}
2+
3+
{% load static %}
4+
{% load bootstrap4 %}
5+
6+
{% block content %}
7+
<h1>Disabled Account</h1>
8+
9+
<p>
10+
Your account has been disabled. Please contact the administrator at <a href="mailto:{{contact_email}}">{{contact_email}}</a> and log out.
11+
</p>
12+
13+
{% endblock content %}

src/templates/base/account/dev_login.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends "base.html" %}
22

3-
{% load staticfiles %}
3+
{% load static %}
44
{% load bootstrap4 %}
55

66
{% block content %}

0 commit comments

Comments
 (0)