diff --git a/UWEFlix/__pycache__/admin.cpython-310.pyc b/UWEFlix/__pycache__/admin.cpython-310.pyc index d02336860b1762f7d07e2b7b822f465279c8da4f..bdc586f87994b79e78e89e4b853c8653b057d018 100644 Binary files a/UWEFlix/__pycache__/admin.cpython-310.pyc and b/UWEFlix/__pycache__/admin.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/backends.cpython-310.pyc b/UWEFlix/__pycache__/backends.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a7e3d95e40f39f9c27107d92a9a3a768bb406028 Binary files /dev/null and b/UWEFlix/__pycache__/backends.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/forms.cpython-310.pyc b/UWEFlix/__pycache__/forms.cpython-310.pyc index 22bf2f985c7f040e38e67fec4188822fd2e3b5ee..e322f25b7ef066158689cac9fa3b7f7f1f04dac1 100644 Binary files a/UWEFlix/__pycache__/forms.cpython-310.pyc and b/UWEFlix/__pycache__/forms.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/models.cpython-310.pyc b/UWEFlix/__pycache__/models.cpython-310.pyc index 46c496e48bc2b80aec9dfa593c9cb17240bb91db..8643d3b93934b8fb0a321e29f14b243e6a3d1767 100644 Binary files a/UWEFlix/__pycache__/models.cpython-310.pyc and b/UWEFlix/__pycache__/models.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/urls.cpython-310.pyc b/UWEFlix/__pycache__/urls.cpython-310.pyc index 760832cdd2c61796b5bc977cc78147eacdb52aac..e1612201c8f8d5ae8f628fa318883aada999f31d 100644 Binary files a/UWEFlix/__pycache__/urls.cpython-310.pyc and b/UWEFlix/__pycache__/urls.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/views.cpython-310.pyc b/UWEFlix/__pycache__/views.cpython-310.pyc index eec7c9ae0469e4d4b337dbd9a5be7d32f7135158..d45294247683edadbfb1b4fe25b13c240193ed00 100644 Binary files a/UWEFlix/__pycache__/views.cpython-310.pyc and b/UWEFlix/__pycache__/views.cpython-310.pyc differ diff --git a/UWEFlix/admin.py b/UWEFlix/admin.py index 041322379e705259b58554f406e70cd08225e3e9..774c6cf07da5b92dee57c18606054968421c3cb2 100644 --- a/UWEFlix/admin.py +++ b/UWEFlix/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import CinemaManager, User, AccountManager +from .models import User, ClubRepresentative # Register your models here. -admin.site.register(User) \ No newline at end of file +admin.site.register(User) +admin.site.register(ClubRepresentative) \ No newline at end of file diff --git a/UWEFlix/backends.py b/UWEFlix/backends.py new file mode 100644 index 0000000000000000000000000000000000000000..30ad09f3aea6f7c6ed67c354d0f161683ecd8b2a --- /dev/null +++ b/UWEFlix/backends.py @@ -0,0 +1,16 @@ +from django.contrib.auth.backends import ModelBackend +from .models import ClubRepresentative + +class ClubRepresentativeBackend(ModelBackend): + def authenticate(self, request, **kwargs): + username = kwargs.get('username') + password = kwargs.get('password') + if not username or not password: + return None + try: + club_rep = ClubRepresentative.objects.get(representative_id=username) + except ClubRepresentative.DoesNotExist: + return None + if club_rep.check_password(password): + return club_rep + return None \ No newline at end of file diff --git a/UWEFlix/forms.py b/UWEFlix/forms.py index 8a52ca9fc687c011893feb5d062d4c2e217f7c99..c8111b894fd25a6a78d7708aec7f08d93cca6a4c 100644 --- a/UWEFlix/forms.py +++ b/UWEFlix/forms.py @@ -26,7 +26,11 @@ class ClubForm(forms.ModelForm): class ClubRepresentativeForm(forms.ModelForm): class Meta: model = ClubRepresentative - fields = ['email', 'first_name', 'last_name', 'representative_id'] + fields = ['email', 'first_name', 'last_name', 'password'] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['password'].widget.attrs.update({'autocomplete': 'new-password'}) class ElevateUserForm(forms.ModelForm): user = forms.ModelChoiceField(queryset=User.objects.all().filter(is_rep=False)) diff --git a/UWEFlix/templates/club_rep_login.html b/UWEFlix/templates/club_rep_login.html new file mode 100644 index 0000000000000000000000000000000000000000..f6aa62d9a41004b53dd8608cd4671c0f2cc871bf --- /dev/null +++ b/UWEFlix/templates/club_rep_login.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} {% load static %} {% block content %} + +<div class="container mt-5"> + <div class="row"> + <div class="col-md-6 offset-md-3"> + <form + class="form-signin" + method="post" + action="{% url 'club_rep_login' %}" + > + {% csrf_token %} + <div class="form-group"> + <label for="inputRepID">Representative ID</label> + <select class="form-control" id="inputRepID" name="inputRepID"> + {% for club_rep in club_reps %} + <option value="{{ club_rep.representative_id }}"> + {{ club_rep.representative_id }} + </option> + {% endfor %} + </select> + </div> + <div class="form-group"> + <label for="inputPassword">Password</label> + <input + type="password" + class="form-control" + id="inputPassword" + name="inputPassword" + required + /> + </div> + <button class="btn btn-lg btn-primary btn-block" type="submit"> + Sign in + </button> + <a + href="{% url 'register' %}" + class="btn btn-lg btn-secondary btn-block mt-2" + >Sign up</a + > + </form> + </div> + </div> +</div> + +{% endblock %} diff --git a/UWEFlix/templates/login.html b/UWEFlix/templates/login.html index fb7893a33bbb7f7e0d7733e52579a4c12b797c38..811c388d4cd45b8010210422ab9cb65f7feb1488 100644 --- a/UWEFlix/templates/login.html +++ b/UWEFlix/templates/login.html @@ -1,30 +1,55 @@ -{% extends 'base.html' %} -{% load static %} - -{% block content %} +{% extends 'base.html' %} {% load static %} {% block content %} <div class="container mt-5"> <div class="row"> <div class="col-md-6 offset-md-3"> <form class="form-signin" method="post" action="{% url 'login' %}"> {% csrf_token %} - <div class="form-group"> - <label for="inputUsername">Username</label> - <input type="text" class="form-control" id="inputUsername" name="inputUsername" required> - </div> - <div class="form-group"> - <label for="inputPassword">Password</label> - <input type="password" class="form-control" id="inputPassword" name="inputPassword" required> + <div class="form-group"> + <label for="inputUsername">Username</label> + <input + type="text" + class="form-control" + id="inputUsername" + name="inputUsername" + required + /> + </div> + <div class="form-group"> + <label for="inputPassword">Password</label> + <input + type="password" + class="form-control" + id="inputPassword" + name="inputPassword" + required + /> </div> <div class="form-group form-check"> - <input type="checkbox" class="form-check-input" id="rememberMe" value="remember-me"> + <input + type="checkbox" + class="form-check-input" + id="rememberMe" + value="remember-me" + /> <label class="form-check-label" for="rememberMe">Remember me</label> </div> - <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> - <a href="{% url 'register' %}" class="btn btn-lg btn-secondary btn-block mt-2">Sign up</a> + <button class="btn btn-lg btn-primary btn-block" type="submit"> + Sign in + </button> + <a + href="{% url 'register' %}" + class="btn btn-lg btn-secondary btn-block mt-2" + >Sign up</a + > + <a + href="{% url 'club_rep_login' %}" + class="btn btn-lg btn-info btn-block mt-2" + >Club Representative Login</a + > </form> </div> </div> </div> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/UWEFlix/templates/update_representative.html b/UWEFlix/templates/update_representative.html index 38dd6128c60393e0ee7071517cc361f6e109f596..8a388a40e5a8801e8dc1860f48ec73ccf0d1a0f5 100644 --- a/UWEFlix/templates/update_representative.html +++ b/UWEFlix/templates/update_representative.html @@ -1,35 +1,72 @@ -{% extends "base.html" %} -{% load static %} +{% extends "base.html" %} {% load static %} {% block content %} -{% block content %} - - <!-- Use Bootstrap's grid system to structure the layout --> - <div class="container mt-5"> - <div class="row justify-content-center"> - <div class="col-md-6"> - <!-- Add the update form --> - <form method="post" class="form-signup"> - {% csrf_token %} - <h1 class="h3 mb-3 font-weight-normal text-center">Update Representative for {{ club.name }}</h1> - <div class="form-group"> - <label for="email">Email</label> - <input type="email" name="email" class="form-control" required> - </div> - <div class="form-group"> - <label for="first_name">First Name</label> - <input type="text" name="first_name" class="form-control" required> - </div> - <div class="form-group"> - <label for="last_name">Last Name</label> - <input type="text" name="last_name" class="form-control" required> - </div> - <div class="form-group"> - <label for="representative_id">Representative ID (cannot be edited)</label> - <input type="text" name="representative_id" class="form-control" required disabled value="{{ representative.representative_id }}"> - </div> - <button class="btn btn-lg btn-primary btn-block" type="submit">Update</button> - </form> - </div> +<!-- Use Bootstrap's grid system to structure the layout --> +<div class="container mt-5"> + <div class="row justify-content-center"> + <div class="col-md-6"> + <!-- Add the update form --> + <form method="post" class="form-signup"> + {% csrf_token %} + <h1 class="h3 mb-3 font-weight-normal text-center"> + Update Representative for {{ club.name }} + </h1> + <div class="form-group"> + <label for="email">Email</label> + <input + type="email" + name="email" + class="form-control" + value="{{ representative.email }}" + required + /> + </div> + <div class="form-group"> + <label for="first_name">First Name</label> + <input + type="text" + name="first_name" + class="form-control" + value="{{ representative.first_name }}" + required + /> + </div> + <div class="form-group"> + <label for="last_name">Last Name</label> + <input + type="text" + name="last_name" + class="form-control" + value="{{ representative.last_name }}" + required + /> + </div> + <div class="form-group"> + <label for="representative_id" + >Representative ID (cannot be edited)</label + > + <input + type="text" + name="representative_id" + class="form-control" + required + disabled + value="{{ representative.representative_id }}" + /> + </div> + <div class="form-group"> + <label for="password">Password</label> + <input + type="password" + name="password" + class="form-control" + required + /> + </div> + <button class="btn btn-lg btn-primary btn-block" type="submit"> + Update + </button> + </form> </div> </div> -{% endblock %} \ No newline at end of file +</div> +{% endblock %} diff --git a/UWEFlix/urls.py b/UWEFlix/urls.py index c6d1620c97dcfb6265d3704f1e54997d414b8c2c..2cf73e4f89db2c2ad9f2bf5c6f0b6b774d27a775 100644 --- a/UWEFlix/urls.py +++ b/UWEFlix/urls.py @@ -33,5 +33,6 @@ urlpatterns = [ path('manage_clubs/<int:pk>/generate_statement/', views.statement_generate, name='generate_statement'), path('manage_clubs/<int:pk>/manage_statements/<int:st_pk>/update/', views.statement_update, name='update_statement'), path('manage_clubs/<int:pk>/manage_statements/<int:st_pk>/delete/', views.statement_delete, name='delete_statement'), - path('create_film/', views.film_create, name='create_film') + path('create_film/', views.film_create, name='create_film'), + path('club_rep_login/', views.club_rep_login, name='club_rep_login'), ] diff --git a/UWEFlix/views.py b/UWEFlix/views.py index ac929b9a1e20243fbc849d09f7fcb13d727b0ad3..c98037f145c3ec9f7caad5e8c6cbd60be307500e 100644 --- a/UWEFlix/views.py +++ b/UWEFlix/views.py @@ -85,6 +85,28 @@ def login_view(request): # Display the login form return render(request, 'login.html') +def club_rep_login(request): + if request.method == 'POST': + rep_id = request.POST.get('inputRepID') + print(rep_id) + password = request.POST.get('inputPassword') + club_rep = authenticate(request, username=rep_id, password=password) + print(club_rep) + if club_rep is not None: + login(request, club_rep) + return redirect('index') + else: + error_message="Invalid representative ID or password" + print(error_message) + context = {'error_message': error_message} + return render(request, 'club_rep_login.html', context) + + else: + club_reps = ClubRepresentative.objects.all() + print(club_reps) + context = {'club_reps': club_reps} + return render(request, 'club_rep_login.html', context) + def logout_view(request): logout(request) @@ -122,6 +144,7 @@ def register_view(request): print(form.errors) form = UserRegistrationForm() return render(request, 'register.html', {'form': form, 'perms': perms}) + def create_cinema(request): @@ -513,15 +536,21 @@ def representative_update(request, pk): club = get_object_or_404(Club, pk=pk) representative = club.representative.clubrepresentative if request.method == 'POST': + print('request post') form = ClubRepresentativeForm(request.POST, instance=representative) if form.is_valid(): + print('club rep form valid') form.save() return redirect('manage_clubs') - form = ClubRepresentativeForm(instance=representative, initial={'representative_id': representative.representative_id}) + else: + print(form.errors) + else: + form = ClubRepresentativeForm(instance=representative, initial={'representative_id': representative.representative_id}) context = {'form': form, 'user': request.user, 'club': club, 'representative': representative, 'perms': perms} return render(request, 'update_representative.html', context) + def statements_list(request, pk): perms = get_user_permissions(request) if perms == '0' or perms == '1': diff --git a/db.sqlite3 b/db.sqlite3 index 34d1f8c7b073d4ffd063b0c7284c21f5d2841a11..53a86735289183bf6fcca84f6854463cc5430b9c 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/web_project/__pycache__/settings.cpython-310.pyc b/web_project/__pycache__/settings.cpython-310.pyc index 97389ba5a6e36e3f4ee2e62e81669f7757442a38..679ee8f1ce3bb77b7d9951a79b0cb59454636db5 100644 Binary files a/web_project/__pycache__/settings.cpython-310.pyc and b/web_project/__pycache__/settings.cpython-310.pyc differ diff --git a/web_project/settings.py b/web_project/settings.py index 600bc33d7fb66cc91eee7947b1b862781e15fa14..f1c0288853f2dc7e0ff07ef0457d4379db263069 100644 --- a/web_project/settings.py +++ b/web_project/settings.py @@ -126,6 +126,9 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' AUTH_USER_MODEL = 'UWEFlix.User' +AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend', 'UWEFlix.backends.ClubRepresentativeBackend',] + + GRAPH_MODELS = { "all_applications": True, "group_models": True,