Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions essenza/essenza/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.contrib import admin
from django.urls import path, include
from django.http import HttpResponse
from info import views

from info.views import info_view
from product.views import EscaparateView
def home(request):
html = """
<html>
Expand Down Expand Up @@ -82,10 +82,9 @@ def home(request):

urlpatterns = [
path('', home, name='home'),
path('info/', views.info_view, name='info-home'),
path('info/', info_view, name='info-home'),
path("user/", include("user.urls")),
path('user/login/', include('user.urls')),
path("accounts/", include("django.contrib.auth.urls")),
path('admin/', admin.site.urls)
path('admin/', admin.site.urls),
path('escaparate/', EscaparateView.as_view(), name='escaparate')
]

5 changes: 4 additions & 1 deletion essenza/product/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.shortcuts import render
from django.views import View

# Create your views here.
class EscaparateView(View):
def get(self, request):
return render(request, 'product/escaparate.html')
122 changes: 122 additions & 0 deletions essenza/templates/product/escaparate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{% load static %}
<!doctype html>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Escaparate · Essenza</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
body {
margin: 0;
background-color: #faf7f2;
font-family: 'Segoe UI', Arial, sans-serif;
}

/* ====== CABECERA ====== */
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 14px 30px;
background-color: #fff;
border-bottom: 2px solid #c06b3e;
}

.brand {
font-size: 32px;
color: #c06b3e;
font-weight: bold;
letter-spacing: 1px;
}

.search-bar {
flex: 1;
margin: 0 20px;
}

.search-bar input {
width: 100%;
max-width: 380px;
padding: 8px 12px;
border: 1px solid #ccc;
border-radius: 20px;
background: #fafafa;
}

.logout-btn {
background-color: #c06b3e;
color: #fff;
border: none;
border-radius: 20px;
padding: 8px 16px;
cursor: pointer;
font-size: 14px;
transition: background-color .3s;
}

.logout-btn:hover {
background-color: #a35a34;
}

/* ====== ESCAPARATE ====== */
main {
max-width: 1100px;
margin: 40px auto;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 20px;
padding: 0 24px;
}

.product-card {
background: #fff;
border: 1px solid #eee;
border-radius: 12px;
box-shadow: 0 2px 10px rgba(0, 0, 0, .05);
text-align: center;
padding: 16px;
transition: transform .2s ease;
}

.product-card:hover {
transform: translateY(-4px);
}

.product-card img {
width: 100%;
height: 180px;
object-fit: cover;
border-radius: 10px;
}

.product-name {
font-size: 15px;
color: #333;
margin-top: 10px;
font-weight: 500;
}

.product-price {
color: #c06b3e;
font-weight: bold;
margin-top: 6px;
}
</style>
</head>

<body>
<header>
<div class="brand">ESSENZA</div>

<div class="search-bar">
<input type="text" placeholder="Buscar...">
</div>

<form action="{% url 'logout' %}" method="post" style="margin:0;">
{% csrf_token %}
<button formaction="{% url 'home' %}" type="submit" class="logout-btn">Log out</button>
</form>
</header>
</body>
</html>
4 changes: 1 addition & 3 deletions essenza/templates/user/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ <h1 class="brand">ESSENZA</h1>

<button type="submit" class="btn-primary">Iniciar sesión</button>

<p class="forgot">
<a href="{% url 'password_reset' %}">¿Has olvidado la contraseña?</a>
</p>

</form>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions essenza/user/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@

urlpatterns = [
path('login/', views.LoginView.as_view(), name='login'),
path('logout/', views.LogoutView.as_view(), name='logout'),

]

31 changes: 25 additions & 6 deletions essenza/user/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from django.shortcuts import render, redirect
from django.views import View
from django.contrib.auth import authenticate, login

from essenza.urls import home
from django.contrib.auth import authenticate, login, logout
from .forms import LoginForm


class LoginView(View):
form_class = LoginForm
template_name = 'user/login.html'


def get(self, request, *args, **kwargs):
# Si el usuario ya está autenticado, lo mandamos a escaparate
logout(request)
if request.user.is_authenticated:
return redirect('home')
return redirect('escaparate')
# Si no está autenticado, renderiza el formulario de login
return render(request, self.template_name, {'form': self.form_class()})

def post(self, request, *args, **kwargs):
Expand All @@ -22,13 +22,32 @@ def post(self, request, *args, **kwargs):
email = form.cleaned_data["email"]
password = form.cleaned_data["password"]

# Autenticamos al usuario
user = authenticate(request, username=email, password=password)

if user is not None:
login(request, user)
return redirect('home')
# Redirige al escaparate después del login
return redirect('escaparate')
else:
# Si falla el login, muestra error en el formulario
form.add_error(None, "Usuario o contraseña incorrectos")

return render(request, self.template_name, {'form': form})


class LogoutView(View):
"""Cierra la sesión y borra la cookie de sesión."""

def get(self, request):
logout(request)
response = redirect('home')
# 🔥 borra cookie de sesión en el navegador
response.delete_cookie('sessionid')
return response

def post(self, request):
logout(request)
response = redirect('home')
response.delete_cookie('sessionid')
return response