diff --git a/gestaoRaul/clients/__pycache__/views.cpython-310.pyc b/gestaoRaul/clients/__pycache__/views.cpython-310.pyc index 652702f..0ec33b4 100644 Binary files a/gestaoRaul/clients/__pycache__/views.cpython-310.pyc and b/gestaoRaul/clients/__pycache__/views.cpython-310.pyc differ diff --git a/gestaoRaul/clients/views.py b/gestaoRaul/clients/views.py index b7fcd2b..17f5bf0 100644 --- a/gestaoRaul/clients/views.py +++ b/gestaoRaul/clients/views.py @@ -1,6 +1,8 @@ from django.shortcuts import render +from django.contrib.auth.models import User + +from gestaoRaul.decorators import group_required -# Create your views here. def clients(request): return render(request, 'clients.html') \ No newline at end of file diff --git a/gestaoRaul/db.sqlite3 b/gestaoRaul/db.sqlite3 index b65c960..eacf04f 100644 Binary files a/gestaoRaul/db.sqlite3 and b/gestaoRaul/db.sqlite3 differ diff --git a/gestaoRaul/gestaoRaul/__pycache__/decorators.cpython-310.pyc b/gestaoRaul/gestaoRaul/__pycache__/decorators.cpython-310.pyc index de1ff3c..09f13be 100644 Binary files a/gestaoRaul/gestaoRaul/__pycache__/decorators.cpython-310.pyc and b/gestaoRaul/gestaoRaul/__pycache__/decorators.cpython-310.pyc differ diff --git a/gestaoRaul/gestaoRaul/__pycache__/settings.cpython-310.pyc b/gestaoRaul/gestaoRaul/__pycache__/settings.cpython-310.pyc index eb19c77..8748c4c 100644 Binary files a/gestaoRaul/gestaoRaul/__pycache__/settings.cpython-310.pyc and b/gestaoRaul/gestaoRaul/__pycache__/settings.cpython-310.pyc differ diff --git a/gestaoRaul/gestaoRaul/__pycache__/urls.cpython-310.pyc b/gestaoRaul/gestaoRaul/__pycache__/urls.cpython-310.pyc index b263974..5e38b98 100644 Binary files a/gestaoRaul/gestaoRaul/__pycache__/urls.cpython-310.pyc and b/gestaoRaul/gestaoRaul/__pycache__/urls.cpython-310.pyc differ diff --git a/gestaoRaul/gestaoRaul/decorators.py b/gestaoRaul/gestaoRaul/decorators.py index 22df2c4..6caa715 100644 --- a/gestaoRaul/gestaoRaul/decorators.py +++ b/gestaoRaul/gestaoRaul/decorators.py @@ -1,14 +1,17 @@ from django.utils.decorators import method_decorator -from django.http import HttpResponseForbidden +from django.http import HttpResponseForbidden, HttpResponseRedirect def group_required(groupName): def decorator(view_function): def wrapper(request, *args, **kwargs): - if request.user.groups.filter(name=groupName).exists(): - return view_function(request, *args, **kwargs) + if request.user.is_authenticated: + if request.user.groups.filter(name=groupName).exists(): + return view_function(request, *args, **kwargs) + else: + return HttpResponseForbidden('tu nao tem acesso rapa') else: - return HttpResponseForbidden('tu nao tem acesso rapa') + return HttpResponseForbidden('Direcionar para tela de login aqui') return wrapper return decorator diff --git a/gestaoRaul/gestaoRaul/settings.py b/gestaoRaul/gestaoRaul/settings.py index 914c889..50d457e 100644 --- a/gestaoRaul/gestaoRaul/settings.py +++ b/gestaoRaul/gestaoRaul/settings.py @@ -54,6 +54,7 @@ INSTALLED_APPS = [ 'payments', 'balcao', 'orders', + 'login', ] MIDDLEWARE = [ diff --git a/gestaoRaul/gestaoRaul/urls.py b/gestaoRaul/gestaoRaul/urls.py index a25719b..df33d14 100644 --- a/gestaoRaul/gestaoRaul/urls.py +++ b/gestaoRaul/gestaoRaul/urls.py @@ -20,6 +20,7 @@ from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include('home.urls')), + path('login/', include('login.urls')), path('products/', include('products.urls')), path('mesas/', include('mesas.urls')), path('typePay/', include('typePay.urls')), diff --git a/gestaoRaul/home/__pycache__/views.cpython-310.pyc b/gestaoRaul/home/__pycache__/views.cpython-310.pyc index 3e326ca..6ae4b8b 100644 Binary files a/gestaoRaul/home/__pycache__/views.cpython-310.pyc and b/gestaoRaul/home/__pycache__/views.cpython-310.pyc differ diff --git a/gestaoRaul/home/views.py b/gestaoRaul/home/views.py index 827ce91..9b656a9 100644 --- a/gestaoRaul/home/views.py +++ b/gestaoRaul/home/views.py @@ -3,6 +3,8 @@ from django.db.models import Sum from django.db.models import Count, F from django.http import JsonResponse, HttpResponse from django.contrib.admin.views.decorators import staff_member_required +from django.contrib.auth.models import User + from comandas.models import ProductComanda @@ -10,7 +12,6 @@ from orders.models import Order from payments.models import Payments from gestaoRaul.decorators import group_required - @group_required(groupName='Gerente') def home(request): total_pagamentos = Payments.objects.aggregate(total=Sum('value'))['total'] @@ -25,6 +26,9 @@ def home(request): @group_required(groupName='Gerente') def chartCuisine(request): + print(request.user.id) + print(request.user.is_authenticated) + # fulano = User() tFila = [] tPreparando = [] tFinalizado = [] diff --git a/gestaoRaul/login/__pycache__/urls.cpython-310.pyc b/gestaoRaul/login/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..aca3532 Binary files /dev/null and b/gestaoRaul/login/__pycache__/urls.cpython-310.pyc differ diff --git a/gestaoRaul/login/__pycache__/views.cpython-310.pyc b/gestaoRaul/login/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..02fd5b4 Binary files /dev/null and b/gestaoRaul/login/__pycache__/views.cpython-310.pyc differ diff --git a/gestaoRaul/login/templates/login.html b/gestaoRaul/login/templates/login.html new file mode 100644 index 0000000..db0a31d --- /dev/null +++ b/gestaoRaul/login/templates/login.html @@ -0,0 +1,13 @@ + + + + Login + + +
+ {% csrf_token %} + {{ form.as_p }} + +
+ + \ No newline at end of file diff --git a/gestaoRaul/login/urls.py b/gestaoRaul/login/urls.py new file mode 100644 index 0000000..65294c6 --- /dev/null +++ b/gestaoRaul/login/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.login_view, name='login'), +] \ No newline at end of file diff --git a/gestaoRaul/login/views.py b/gestaoRaul/login/views.py new file mode 100644 index 0000000..6079b85 --- /dev/null +++ b/gestaoRaul/login/views.py @@ -0,0 +1,23 @@ +from django.shortcuts import render, redirect +from django.contrib.auth import authenticate, login +from django.contrib.auth.forms import AuthenticationForm + +def login_view(request): + if request.method == 'POST': + form = AuthenticationForm(data=request.POST) + if form.is_valid(): + username = form.cleaned_data.get('username') + password = form.cleaned_data.get('password') + user = authenticate(username=username, password=password) + if user is not None: + login(request, user) + return redirect('home') # Substitua 'home' pelo nome da sua URL inicial + else: + pass + # Mensagem de erro: Credenciais inválidas + else: + pass + # Mensagem de erro: Formulário inválido + else: + form = AuthenticationForm() + return render(request, 'login.html', {'form': form}) \ No newline at end of file