From 6fdbb54cdef90aeebd4e5e029a3205f53f4b6744 Mon Sep 17 00:00:00 2001 From: Brody Wilton <brodywilton@hotmail.com> Date: Mon, 25 Mar 2024 17:34:01 +0000 Subject: [PATCH] restrict dashboard based on user type --- myproject/myapp/templates/pricing.html | 2 +- myproject/myapp/templates/user_page.html | 18 +++++++++++++----- myproject/myapp/views.py | 4 ++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/myproject/myapp/templates/pricing.html b/myproject/myapp/templates/pricing.html index 45b0ad3..78b60c2 100644 --- a/myproject/myapp/templates/pricing.html +++ b/myproject/myapp/templates/pricing.html @@ -42,7 +42,7 @@ </div> <div class="w-full mx-auto max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700"> - <h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Standard plan</h5> + <h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Bulk Purchase</h5> <div class="flex items-baseline text-gray-900 dark:text-white"> <span class="text-3xl font-semibold">£</span> <span class="text-5xl font-extrabold tracking-tight">49</span> diff --git a/myproject/myapp/templates/user_page.html b/myproject/myapp/templates/user_page.html index 2f17994..c6952ce 100644 --- a/myproject/myapp/templates/user_page.html +++ b/myproject/myapp/templates/user_page.html @@ -6,8 +6,12 @@ <h1 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white"> User settings </h1> + <h3 class="mb-4 text-xl font-semibold dark:text-white"> + User type: {{ user_profile.user_type }} + </h3> </div> <!-- Right Content --> + <div class="col-span-full xl:col-auto"> <div class="p-4 mb-4 bg-white border boder-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"> <h3 class="mb-4 text-xl font-semibold dark:text-white">Tokens:</h3> @@ -18,10 +22,12 @@ <a href="{% url 'password_change' %}" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Change Password</a> </div> - {% if 1 %} + + {% if user_profile.user_type == 3 %} <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" > + <h3 class="mb-4 text-xl font-semibold dark:text-white"> Generate Financial Statement </h3> @@ -69,7 +75,8 @@ </form> {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {% endcomment %} </div> - {% endif %} {% if 1 %} + {% endif %} + {% if 1 %} <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" @@ -130,7 +137,7 @@ class="shadow-sm bg-gray-50 border border-gray-300 text-grey-300 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="example@gmail.com" required - >example@gmail.com</span + >{{ user.email }}</span > </div> <div class="col-span-6 sm:col-span-3"> @@ -146,7 +153,7 @@ class="shadow-sm bg-gray-50 border border-gray-300 text-grey-300 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Green" required - >LoginExample</span + >{{ user.username }}</span > </div> </div> @@ -193,7 +200,7 @@ </div> {% if 1 %} {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {%endcomment %} - + {% if user_profile.user_type == 2 %} <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" > @@ -238,6 +245,7 @@ </tbody> </table> </div> + {% endif %} {% endif %} {% comment %} Admin page functionality end {% endcomment %} </div> </div> diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py index 912c1a2..a04cd1b 100644 --- a/myproject/myapp/views.py +++ b/myproject/myapp/views.py @@ -153,11 +153,15 @@ def users(request): admin_dict = json.loads(data_admin.content) user_dict = json.loads(data_user.content) token_count = UserTokenCount.objects.get(user=request.user).token_count + user_profile = request.user.profile + user = request.user # Pass the data as a context variable to the template # !!! ADMIN DATA ONLY DISPLAYED AND GET IF USER IS ADMIN !!! context['admin_data'] = admin_dict['data'] context['user_data'] = user_dict['data'] context['token_count'] = token_count + context['user_profile'] = user_profile + context['user'] = user return render(request, 'user_page.html', context) -- GitLab