@@ -113,6 +114,7 @@
Click the toggle switch next to a user to make them a reviewer.
+ Note that a student needs to sign in before they appear on this list.
diff --git a/Instructor/urls.py b/Instructor/urls.py
index b8c24b7..a5b7e0e 100644
--- a/Instructor/urls.py
+++ b/Instructor/urls.py
@@ -9,6 +9,7 @@ from . import views
urlpatterns = [
path('', views.AdminHomeView.as_view(), name="instructor-home"),
path('users/', views.UserListView.as_view(), name="user-list"),
+ path('users/cleanup/', views.UserClearView.as_view(), name="user-cleanup"),
path('rubric/', views.RubricListView.as_view(), name="rubric-list"),
path('rubric/create/', views.RubricCreateView.as_view(), name="rubric-create"),
path('rubric/edit//', views.RubricEditView.as_view(), name="rubric-edit"),
diff --git a/Instructor/views.py b/Instructor/views.py
index c9d9168..8f83d03 100644
--- a/Instructor/views.py
+++ b/Instructor/views.py
@@ -2,23 +2,38 @@
This file defines the back-end code that runs when a user requests a page for the Instructor app
"""
-from json import JSONDecoder, JSONDecodeError
-
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
-from django.http import Http404
from django.shortcuts import redirect
from django.urls import reverse_lazy
-from django.views.generic import ListView, TemplateView, CreateView, UpdateView, DeleteView
-from jsonschema import validate
-from jsonschema.exceptions import ValidationError as JsonValidationError
+from django.views.generic import View, ListView, TemplateView, CreateView, UpdateView, DeleteView
from Main import models as main_models
from Main.views import IsSuperUserMixin, FormNameMixin, FormAlertMixin, SuccessDeleteMixin
from Users.models import User
+from Users.ldap_auth import LDAPAuthentication, LDAPAuthException
from . import models, forms
+class UserClearView(LoginRequiredMixin, IsSuperUserMixin, View):
+
+ http_method_names = ['post']
+
+ def post(self, request):
+ self.request = request
+ password = self.request.POST.get("userPassword", None)
+ if password is None or password == "":
+ messages.add_message(self.request, messages.ERROR, "Please provide a password")
+ return redirect("user-list")
+ else:
+ try:
+ LDAPAuthentication().delete_old_users(self.request.user.username, password)
+ messages.add_message(self.request, messages.SUCCESS, "Users Cleared Successfully")
+ except LDAPAuthException as error:
+ messages.add_message(self.request, messages.ERROR, error.args[0])
+ return redirect("user-list")
+
+
class AdminHomeView(LoginRequiredMixin, IsSuperUserMixin, TemplateView):
"""
This view shows the Instructor's homepage, where they can view ongoing and completed Reviews
diff --git a/Users/ldap_auth.py b/Users/ldap_auth.py
index 50e1b73..29341e3 100644
--- a/Users/ldap_auth.py
+++ b/Users/ldap_auth.py
@@ -176,7 +176,7 @@ class LDAPAuthentication(BaseBackend):
return None
def delete_old_users(self, username, password):
- conn = Connection(self.server, user=f"{settings.LDAP_DOMAIN}\\{username}",
+ conn = Connection(self.server, user=username,
password=password, authentication=NTLM)
try:
if conn.bind():
@@ -188,10 +188,10 @@ class LDAPAuthentication(BaseBackend):
if len(ldap_users.match("msDs-principalName", user.username)) == 0:
user.delete()
else:
- raise LDAPAuthException("User is not admin")
+ raise LDAPAuthException("You lack permissions to perform this action.")
else:
- raise LDAPAuthException("Invalid Credentials")
+ raise LDAPAuthException("Login failed, check your password and try again.")
except LDAPBindError:
- raise LDAPAuthException("Can't connect to ActiveDirectory")
+ raise LDAPAuthException("Can't connect to ActiveDirectory, please try again later.")
except LDAPSocketOpenError:
- raise LDAPAuthException("Can't connect to ActiveDirectory")
+ raise LDAPAuthException("Can't connect to ActiveDirectory, please try again later.")