Add Nginx configuration, update MEDIA_ROOT path, and enhance email confirmation task
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
|||||||
|
worker_processes auto;
|
||||||
|
|
||||||
|
error_log /var/log/nginx/error.log warn;
|
||||||
|
pid /var/run/nginx.pid;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
|
||||||
|
access_log /var/log/nginx/access.log main;
|
||||||
|
|
||||||
|
sendfile on;
|
||||||
|
tcp_nopush on;
|
||||||
|
tcp_nodelay on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
types_hash_max_size 2048;
|
||||||
|
client_max_body_size 25M;
|
||||||
|
|
||||||
|
upstream django_gunicorn {
|
||||||
|
# Usa el nombre del servicio del contenedor Django/Gunicorn en tu red Docker.
|
||||||
|
# Si en docker-compose el servicio se llama distinto, cámbialo aquí.
|
||||||
|
server django:8000;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
# Archivos estáticos generados por collectstatic.
|
||||||
|
location /static/ {
|
||||||
|
alias /static/;
|
||||||
|
expires 30d;
|
||||||
|
add_header Cache-Control "public, max-age=2592000, immutable";
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Archivos subidos por usuarios.
|
||||||
|
location /media/ {
|
||||||
|
alias /media/;
|
||||||
|
expires 7d;
|
||||||
|
add_header Cache-Control "public, max-age=604800";
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://django_gunicorn;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Port $server_port;
|
||||||
|
|
||||||
|
proxy_redirect off;
|
||||||
|
proxy_read_timeout 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
-1
@@ -212,7 +212,7 @@ if SASS_BINARY:
|
|||||||
|
|
||||||
# Media files (User uploads)
|
# Media files (User uploads)
|
||||||
MEDIA_URL = 'media/'
|
MEDIA_URL = 'media/'
|
||||||
MEDIA_ROOT = BASE_DIR / 'tienda' / 'static' / 'media'
|
MEDIA_ROOT = Path(os.getenv('MEDIA_ROOT', '/app/media'))
|
||||||
|
|
||||||
# Redis Configuration
|
# Redis Configuration
|
||||||
CACHES = {
|
CACHES = {
|
||||||
@@ -271,6 +271,19 @@ AUTH_USER_MODEL = 'tienda.User'
|
|||||||
DOMAIN = os.getenv("DOMAIN", "localhost")
|
DOMAIN = os.getenv("DOMAIN", "localhost")
|
||||||
PROTOCOL = os.getenv("PROTOCOL", "http")
|
PROTOCOL = os.getenv("PROTOCOL", "http")
|
||||||
|
|
||||||
|
default_csrf_trusted_origins = []
|
||||||
|
if DOMAIN:
|
||||||
|
default_csrf_trusted_origins.append(f"{PROTOCOL}://{DOMAIN}")
|
||||||
|
|
||||||
|
for host in ALLOWED_HOSTS:
|
||||||
|
if host and host != '*':
|
||||||
|
default_csrf_trusted_origins.append(f"{PROTOCOL}://{host}")
|
||||||
|
|
||||||
|
CSRF_TRUSTED_ORIGINS = env_list(
|
||||||
|
'CSRF_TRUSTED_ORIGINS',
|
||||||
|
list(dict.fromkeys(default_csrf_trusted_origins)),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO').upper()
|
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO').upper()
|
||||||
LOG_DIR = Path(os.getenv('LOG_DIR', BASE_DIR / 'logs'))
|
LOG_DIR = Path(os.getenv('LOG_DIR', BASE_DIR / 'logs'))
|
||||||
|
|||||||
+17
-3
@@ -1,7 +1,21 @@
|
|||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
from django.conf import settings
|
||||||
from .utilities import send_email
|
from .utilities import send_email
|
||||||
from .vars import login_message
|
from .vars import login_message, verify_message
|
||||||
|
import random, string
|
||||||
|
|
||||||
|
from .models import User, VerificationCode
|
||||||
|
@shared_task
|
||||||
|
def enviar_correo_bienvenida(email_usuario: str, nombre_usuario: str):
|
||||||
|
send_email(email_usuario, "Inicio de Sesión correcto", login_message.format(name = nombre_usuario))
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def enviar_correo_bienvenida(email_usuario, nombre_usuario):
|
def enviar_correo_confirmacion(usuario: User):
|
||||||
send_email(email_usuario, "Inicio de Sesión correcto", login_message.format(name = nombre_usuario))
|
code = VerificationCode.objects.create(
|
||||||
|
user = usuario,
|
||||||
|
code_mode = VerificationCode.VerificationModes.VERIFY_ACCOUNT,
|
||||||
|
code = ''.join(random.choices(string.digits, k=12))
|
||||||
|
)
|
||||||
|
|
||||||
|
message = verify_message.format(name = usuario.get_full_name(), protocol = settings.PROTOCOL, domain = settings.DOMAIN, code = code.code)
|
||||||
|
email_result = send_email(usuario.email, "Verificación de cuenta", message)
|
||||||
+2
-13
@@ -5,16 +5,13 @@ from django.contrib.auth import authenticate, login as auth_login, logout as aut
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from .models import User, Product, Category, Cart, CartItem, Image, Order, OrderItem, OrderMessage, ShippingAddress, VerificationCode
|
from .models import User, Product, Category, Cart, CartItem, Image, Order, OrderItem, OrderMessage, ShippingAddress, VerificationCode
|
||||||
from .utilities import send_email
|
|
||||||
from . import tasks
|
from . import tasks
|
||||||
from .vars import (
|
from .vars import (
|
||||||
PAGE_SIZE,
|
PAGE_SIZE,
|
||||||
VAT_RATE,
|
VAT_RATE,
|
||||||
SHIPPING_COUNTRY,
|
SHIPPING_COUNTRY,
|
||||||
ALMERIA_POSTAL_CODE_PREFIX,
|
ALMERIA_POSTAL_CODE_PREFIX,
|
||||||
ALMERIA_MUNICIPALITIES_DISPLAY,
|
ALMERIA_MUNICIPALITIES_DISPLAY
|
||||||
verify_message,
|
|
||||||
login_message
|
|
||||||
)
|
)
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
@@ -239,16 +236,8 @@ def register(request: HttpRequest):
|
|||||||
client_ip,
|
client_ip,
|
||||||
)
|
)
|
||||||
|
|
||||||
ver_code = ''.join(random.choices(string.digits, k=12))
|
|
||||||
|
|
||||||
codigo = VerificationCode.objects.create(
|
tasks.enviar_correo_confirmacion.delay(user)
|
||||||
user = user,
|
|
||||||
code = ver_code,
|
|
||||||
code_mode = VerificationCode.VerificationModes.VERIFY_ACCOUNT
|
|
||||||
)
|
|
||||||
message = verify_message.format(name = name, protocol = settings.PROTOCOL, domain = settings.DOMAIN, code = ver_code)
|
|
||||||
email_result = send_email(email, "Verificación de cuenta", message)
|
|
||||||
|
|
||||||
messages.success(request, f"¡Cuenta creada exitosamente! Por favor, verifica tu correo entrando al Link enviado.")
|
messages.success(request, f"¡Cuenta creada exitosamente! Por favor, verifica tu correo entrando al Link enviado.")
|
||||||
return redirect("index")
|
return redirect("index")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user