From f6d975afc227de7e8af4f746c6a72c2136881ca9 Mon Sep 17 00:00:00 2001
From: SyahrulApr86 <apriansyah.syahrul@gmail.com>
Date: Tue, 13 Dec 2022 20:21:04 +0700
Subject: [PATCH] fix navbar

---
 account/forms.py      |  4 ++++
 account/views.py      | 16 ++++++++++++++++
 templates/navbar.html | 10 +++-------
 trigger_2/forms.py    |  2 ++
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/account/forms.py b/account/forms.py
index c78f9c7..ca3eb22 100644
--- a/account/forms.py
+++ b/account/forms.py
@@ -23,6 +23,10 @@ class RegisterFormAdmin(forms.Form):
     no_hp = forms.CharField(label='No HP', max_length=20, widget=forms.TextInput(
         attrs={'class': 'form-control', 'placeholder': 'No HP'}))
 
+    error_messages = {
+        'required': 'This field is required',
+    }
+
 
 class RegisterFormPelanggan(forms.Form):
     email = forms.EmailField(label='Email', max_length=50, widget=forms.TextInput(
diff --git a/account/views.py b/account/views.py
index 5ce9038..77110cb 100644
--- a/account/views.py
+++ b/account/views.py
@@ -728,10 +728,18 @@ def register_kurir(request):
 
 
 def dashboard_admin(request):
+    role = request.COOKIES.get('role')
+    if role != 'admin':
+        return HttpResponseRedirect(reverse('account:show_main'))
+
     return render(request, 'dashboard_admin.html')
 
 
 def profile_restoran(request, email):
+    role = request.COOKIES.get('role')
+    if role != 'restaurant':
+        return HttpResponseRedirect(reverse('account:show_main'))
+
     cursor.execute(
         f'select * from user_acc u, transaction_actor t, restaurant r where u.email = \'{email}\' and u.email = t.email and t.email = r.email')
     record = cursor.fetchall()
@@ -755,6 +763,10 @@ def profile_restoran(request, email):
 
 
 def profile_pelanggan(request, email):
+    role = request.COOKIES.get('role')
+    if role != 'customer':
+        return HttpResponseRedirect(reverse('account:show_main'))
+
     cursor.execute(
         f'select u.email, password, fname || \' \' || lname as name, phonenum, nik, bankname, accountno, birthdate, sex, restopay, adminid from user_acc u, transaction_actor t, customer c where u.email = \'{email}\' and u.email = t.email and t.email = c.email')
     record = cursor.fetchall()
@@ -766,6 +778,10 @@ def profile_pelanggan(request, email):
 
 
 def profile_kurir(request, email):
+    role = request.COOKIES.get('role')
+    if role != 'courier':
+        return HttpResponseRedirect(reverse('account:show_main'))
+
     cursor.execute(
         f'select * from user_acc u, transaction_actor t, courier c where u.email = \'{email}\' and u.email = t.email and t.email = c.email')
     record = cursor.fetchall()
diff --git a/templates/navbar.html b/templates/navbar.html
index db4fc9f..6a75f86 100644
--- a/templates/navbar.html
+++ b/templates/navbar.html
@@ -63,6 +63,7 @@
                 </div>
             </div>
         </div>   
+        
     <!-- {admin start} -->
     {% if role == 'admin' %}
     <div @click.away="open = false" class="relative" x-data="{ open: false }">
@@ -237,12 +238,7 @@
     </div>
     {% endif %}
     <!-- admin end -->
-
-        <!-- pelanggan start -->
-        {% if role == 'customer' and adminid != None %}
-        <div class="md:mx-5 my-3 md:my-0  text-center">
-            <a href="{% url 'trigger3:daftar_restoran' %}" class="hover:text-[#DBC8AC] hover:text-lg duration-500 whitespace-nowrap">Daftar Restoran dan Makanan</a>
-        </div>
+    
     <!-- pelanggan start -->
     {% if role == 'customer' and adminid != None %}
     <div class="md:mx-5 my-3 md:my-0 text-center">
@@ -369,4 +365,4 @@
             <a href="{% url 'account:logout' %}" class="hover:text-[#DBC8AC] hover:text-lg duration-500">Logout</a>
         </div>
     </div>
-</nav>
+</nav>
\ No newline at end of file
diff --git a/trigger_2/forms.py b/trigger_2/forms.py
index 95dd289..cf582af 100644
--- a/trigger_2/forms.py
+++ b/trigger_2/forms.py
@@ -28,6 +28,8 @@ class FormBuatJamOperasional(forms.Form):
         attrs={'class': 'w-[20rem] h-[2.5rem] rounded-lg border-2 border-gray-300', 'type': 'time'}))
 
 
+
+
 class FormEditJamOperasional(forms.Form):
     # Jam buka time picker
     jam_buka = forms.TimeField(label='Jam Buka', widget=forms.TimeInput(
-- 
GitLab