diff --git a/proyecto/__pycache__/__init__.cpython-314.pyc b/proyecto/__pycache__/__init__.cpython-314.pyc index 3adf1a0..8250ca7 100644 Binary files a/proyecto/__pycache__/__init__.cpython-314.pyc and b/proyecto/__pycache__/__init__.cpython-314.pyc differ diff --git a/proyecto/__pycache__/settings.cpython-314.pyc b/proyecto/__pycache__/settings.cpython-314.pyc index 30642f3..3cb5057 100644 Binary files a/proyecto/__pycache__/settings.cpython-314.pyc and b/proyecto/__pycache__/settings.cpython-314.pyc differ diff --git a/templates/jinja2/emails/reset_pass.html b/templates/jinja2/emails/reset_pass.html new file mode 100644 index 0000000..32dc1a9 --- /dev/null +++ b/templates/jinja2/emails/reset_pass.html @@ -0,0 +1,27 @@ + + + + +
+ + + + + + + + + + +
+

¡Hola {{ name }}!

+
+ alert alert +
+

¡Alguien esta intentando cambiar la contraseña de tu cuenta!

+

Si has sido tu, haga click en el siguiente enlace. Si no, Elimine el correo de inmediato

+

+

Para resetear tu contraseña, Haga click aqui

+

Este email ha sido enviado automaticamente, no responda a este correo.

+
+
\ No newline at end of file diff --git a/tienda/__pycache__/admin.cpython-314.pyc b/tienda/__pycache__/admin.cpython-314.pyc index 1b0d656..bf9e0c8 100644 Binary files a/tienda/__pycache__/admin.cpython-314.pyc and b/tienda/__pycache__/admin.cpython-314.pyc differ diff --git a/tienda/__pycache__/models.cpython-314.pyc b/tienda/__pycache__/models.cpython-314.pyc index 0a69a30..664bcdd 100644 Binary files a/tienda/__pycache__/models.cpython-314.pyc and b/tienda/__pycache__/models.cpython-314.pyc differ diff --git a/tienda/__pycache__/urls.cpython-314.pyc b/tienda/__pycache__/urls.cpython-314.pyc index ab71d24..bcd2369 100644 Binary files a/tienda/__pycache__/urls.cpython-314.pyc and b/tienda/__pycache__/urls.cpython-314.pyc differ diff --git a/tienda/__pycache__/vars.cpython-314.pyc b/tienda/__pycache__/vars.cpython-314.pyc index c41a8a3..1507f0c 100644 Binary files a/tienda/__pycache__/vars.cpython-314.pyc and b/tienda/__pycache__/vars.cpython-314.pyc differ diff --git a/tienda/__pycache__/views.cpython-314.pyc b/tienda/__pycache__/views.cpython-314.pyc index bd15423..30f8c67 100644 Binary files a/tienda/__pycache__/views.cpython-314.pyc and b/tienda/__pycache__/views.cpython-314.pyc differ diff --git a/tienda/migrations/__pycache__/0001_initial.cpython-314.pyc b/tienda/migrations/__pycache__/0001_initial.cpython-314.pyc index 851e7f4..4fa3f99 100644 Binary files a/tienda/migrations/__pycache__/0001_initial.cpython-314.pyc and b/tienda/migrations/__pycache__/0001_initial.cpython-314.pyc differ diff --git a/tienda/migrations/__pycache__/0002_verificationcode_code_mode_and_more.cpython-314.pyc b/tienda/migrations/__pycache__/0002_verificationcode_code_mode_and_more.cpython-314.pyc index d4fc2a6..6d2093c 100644 Binary files a/tienda/migrations/__pycache__/0002_verificationcode_code_mode_and_more.cpython-314.pyc and b/tienda/migrations/__pycache__/0002_verificationcode_code_mode_and_more.cpython-314.pyc differ diff --git a/tienda/tasks.py b/tienda/tasks.py index 8b76165..bdc6503 100644 --- a/tienda/tasks.py +++ b/tienda/tasks.py @@ -18,7 +18,8 @@ def enviar_correo_bienvenida(email_usuario: str, nombre_usuario: str): send_hemail(email_usuario, "Inicio de Sesión correcto", html_content, "Has iniciado sesión...") @shared_task -def enviar_correo_confirmacion(usuario: User): +def enviar_correo_confirmacion(id: int): + usuario = User.objects.get(id=id) code = VerificationCode.objects.create( user = usuario, code_mode = VerificationCode.VerificationModes.VERIFY_ACCOUNT, @@ -26,4 +27,27 @@ def enviar_correo_confirmacion(usuario: User): ) 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) \ No newline at end of file + email_result = send_email(usuario.email, "Verificación de cuenta", message) + +@shared_task +def enviar_correo_recuperacion(email: str): + usuario = User.objects.get(email=email) + if usuario is not None: + ver_code = VerificationCode.objects.create( + code_mode = VerificationCode.VerificationModes.RESET_PASSWORD, + user = usuario, + code = ''.join(random.choices(string.digits, k=12)) + ) + ver_code.save() + html_content = render_to_string( + 'emails/reset_pass.html', + { + "name": usuario.get_full_name(), + "domain": settings.DOMAIN, + "protocol": settings.PROTOCOL, + "code": ver_code.code + }, + using='jinja2' + ) + + send_hemail(email, "Reset de Contraseña", html_content, "Estas reseteando la contraseña...") diff --git a/tienda/templates/tienda/login.html b/tienda/templates/tienda/login.html index dca6fa6..28e9028 100644 --- a/tienda/templates/tienda/login.html +++ b/tienda/templates/tienda/login.html @@ -34,7 +34,7 @@
- ¿Olvidaste tu contraseña? + ¿Olvidaste tu contraseña?

diff --git a/tienda/templates/tienda/reset_password.html b/tienda/templates/tienda/reset_password.html new file mode 100644 index 0000000..5bd80a8 --- /dev/null +++ b/tienda/templates/tienda/reset_password.html @@ -0,0 +1,34 @@ +{% extends "tienda/base.html" %} +{% load static %} + +{% block content %} +
+
+
+
+

Recuperar contraseña

+
+
+
+ {% csrf_token %} + +
+ + +
+ +
+ +
+ +
+ +
+

¿No tienes cuenta? Regístrate aquí

+
+
+
+
+
+
+{% endblock %} diff --git a/tienda/templates/tienda/reset_password_phase2.html b/tienda/templates/tienda/reset_password_phase2.html new file mode 100644 index 0000000..27ce0df --- /dev/null +++ b/tienda/templates/tienda/reset_password_phase2.html @@ -0,0 +1,39 @@ +{% extends "tienda/base.html" %} +{% load static %} + +{% block content %} +
+
+
+
+

Recuperar contraseña

+
+
+
+ {% csrf_token %} + +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+

¿No tienes cuenta? Regístrate aquí

+
+
+
+
+
+
+{% endblock %} diff --git a/tienda/urls.py b/tienda/urls.py index 31fb7af..5978912 100644 --- a/tienda/urls.py +++ b/tienda/urls.py @@ -45,5 +45,7 @@ urlpatterns = [ path("usuario/direcciones//eliminar/", views.eliminar_direccion, name="eliminar_direccion"), path("usuario/mensajes/", views.mensajes_comprador, name="mensajes_comprador"), path("verify/", views.verify, name="verify"), - path("rgpd", views.rgpd, name="rgpd") + path("rgpd", views.rgpd, name="rgpd"), + path("reset-password", views.reset_password, name="reset_password"), + path("reset-password-phase2/", views.reset_password_phase2, name="reset_password_phase2") ] diff --git a/tienda/views.py b/tienda/views.py index e969241..f665639 100644 --- a/tienda/views.py +++ b/tienda/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render, redirect, get_object_or_404 -from django.http import HttpRequest, HttpResponse, JsonResponse +from django.http import Http404, HttpRequest, HttpResponse, JsonResponse from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout from django.contrib.auth.decorators import login_required @@ -237,7 +237,7 @@ def register(request: HttpRequest): ) - tasks.enviar_correo_confirmacion.delay(user) + tasks.enviar_correo_confirmacion.delay(user.id) messages.success(request, f"¡Cuenta creada exitosamente! Por favor, verifica tu correo entrando al Link enviado.") return redirect("index") @@ -1256,4 +1256,41 @@ def reset_password(request: HttpRequest): return render(request, "tienda/reset_password", {}) def rgpd(request: HttpRequest): - return render(request, "tienda/rgpd.html", {}) \ No newline at end of file + return render(request, "tienda/rgpd.html", {}) + +def reset_password(request: HttpRequest): + if request.method == "GET": + return render(request, "tienda/reset_password.html", {}) + else: + tasks.enviar_correo_recuperacion.delay(request.POST["email"]) + messages.info(request, "Si tienes una cuenta con ese correo electronico, se ha enviado un correo con un enlace") + return render(request, "tienda/index.html", {}) + +def reset_password_phase2(request: HttpRequest, code: str): + try: + ver_code = VerificationCode.objects.get(code=code) + except VerificationCode.DoesNotExist: + raise Http404() + + if ver_code.code_mode != VerificationCode.VerificationModes.RESET_PASSWORD: raise Http404() + + + if request.method == "GET": + return render(request, "tienda/reset_password_phase2.html", { + "code": code + }) + elif request.method == "POST": + password = request.POST["password"] + vpassword = request.POST["verify_password"] + if password != vpassword: + messages.error(request, "Las contraseñas no coinciden") + return render(request, "tienda/reset_password_phase2.html", {"code": code}) + + user = ver_code.user + user.set_password(password) + user.save() + messages.success(request, "Se ha cambiado la contraseña!") + return redirect(reverse("index")) + + else: + raise Http404()