mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: page login
This commit is contained in:
Binary file not shown.
@@ -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')
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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.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('Direcionar para tela de login aqui')
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ INSTALLED_APPS = [
|
||||
'payments',
|
||||
'balcao',
|
||||
'orders',
|
||||
'login',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@@ -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')),
|
||||
|
||||
Binary file not shown.
@@ -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 = []
|
||||
|
||||
BIN
gestaoRaul/login/__pycache__/urls.cpython-310.pyc
Normal file
BIN
gestaoRaul/login/__pycache__/urls.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/login/__pycache__/views.cpython-310.pyc
Normal file
BIN
gestaoRaul/login/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
13
gestaoRaul/login/templates/login.html
Normal file
13
gestaoRaul/login/templates/login.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Entrar</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
6
gestaoRaul/login/urls.py
Normal file
6
gestaoRaul/login/urls.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.login_view, name='login'),
|
||||
]
|
||||
23
gestaoRaul/login/views.py
Normal file
23
gestaoRaul/login/views.py
Normal file
@@ -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})
|
||||
Reference in New Issue
Block a user