From 6e97e24bf0a8d1cf71c2921cf4a3779663a41457 Mon Sep 17 00:00:00 2001
From: marnunrey2
Date: Thu, 23 Nov 2023 20:19:39 +0100
Subject: [PATCH 01/16] =?UTF-8?q?feat:=20Creacion=20de=20reseteo=20de=20co?=
=?UTF-8?q?ntrase=C3=B1a=20funcional=20a=20falta=20de=20que=20funcione=20e?=
=?UTF-8?q?nviar=20el=20email?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../templates/authentication/login.html | 2 +
.../authentication/password_reset.html | 35 ++++++++++++++++
.../password_reset_complete.html | 15 +++++++
.../password_reset_confirm.html | 40 +++++++++++++++++++
.../authentication/password_reset_done.html | 15 +++++++
decide/authentication/urls.py | 40 ++++++++++++++++++-
6 files changed, 146 insertions(+), 1 deletion(-)
create mode 100644 decide/authentication/templates/authentication/password_reset.html
create mode 100644 decide/authentication/templates/authentication/password_reset_complete.html
create mode 100644 decide/authentication/templates/authentication/password_reset_confirm.html
create mode 100644 decide/authentication/templates/authentication/password_reset_done.html
diff --git a/decide/authentication/templates/authentication/login.html b/decide/authentication/templates/authentication/login.html
index 4bf3bcee9..ee8e0e360 100644
--- a/decide/authentication/templates/authentication/login.html
+++ b/decide/authentication/templates/authentication/login.html
@@ -93,6 +93,8 @@
Continuar con Google
+
+ Recuperar Contraseña
{% endblock %}
diff --git a/decide/authentication/templates/authentication/password_reset.html b/decide/authentication/templates/authentication/password_reset.html
new file mode 100644
index 000000000..fd7813151
--- /dev/null
+++ b/decide/authentication/templates/authentication/password_reset.html
@@ -0,0 +1,35 @@
+{% extends "base.html" %}
+{% load i18n static %}
+
+{% block title %}Restore password{% endblock %}
+
+{% block extrahead %}
+
+{% endblock %}
+
+{% block content %}
+
+{% endblock %}
diff --git a/decide/authentication/templates/authentication/password_reset_complete.html b/decide/authentication/templates/authentication/password_reset_complete.html
new file mode 100644
index 000000000..6bd10e62c
--- /dev/null
+++ b/decide/authentication/templates/authentication/password_reset_complete.html
@@ -0,0 +1,15 @@
+{% extends "base.html" %}
+{% load i18n static %}
+
+{% block title %}Restore password{% endblock %}
+
+{% block extrahead %}
+
+{% endblock %}
+
+{% block content %}
+
+{% endblock %}
diff --git a/decide/authentication/templates/authentication/password_reset_confirm.html b/decide/authentication/templates/authentication/password_reset_confirm.html
new file mode 100644
index 000000000..f7dbdab31
--- /dev/null
+++ b/decide/authentication/templates/authentication/password_reset_confirm.html
@@ -0,0 +1,40 @@
+{% extends "base.html" %}
+{% load i18n static %}
+
+{% block title %}Restore password{% endblock %}
+
+{% block extrahead %}
+
+{% endblock %}
+
+{% block content %}
+
+{% endblock %}
diff --git a/decide/authentication/templates/authentication/password_reset_done.html b/decide/authentication/templates/authentication/password_reset_done.html
new file mode 100644
index 000000000..a041791b8
--- /dev/null
+++ b/decide/authentication/templates/authentication/password_reset_done.html
@@ -0,0 +1,15 @@
+{% extends "base.html" %}
+{% load i18n static %}
+
+{% block title %}Restore password{% endblock %}
+
+{% block extrahead %}
+
+{% endblock %}
+
+{% block content %}
+
+{% endblock %}
diff --git a/decide/authentication/urls.py b/decide/authentication/urls.py
index 3a0a3daa5..10b005442 100644
--- a/decide/authentication/urls.py
+++ b/decide/authentication/urls.py
@@ -1,7 +1,19 @@
from django.urls import path, include
from rest_framework.authtoken.views import obtain_auth_token
+from django.contrib.auth.views import (
+ PasswordResetView,
+ PasswordResetDoneView,
+ PasswordResetConfirmView,
+ PasswordResetCompleteView,
+)
-from .views import GetUserView, LoginView, LogoutView, RegisterView, ChangePasswordView
+from .views import (
+ GetUserView,
+ LoginView,
+ LogoutView,
+ RegisterView,
+ ChangePasswordView,
+)
urlpatterns = [
path("login/", obtain_auth_token),
@@ -11,4 +23,30 @@
path("accounts/", include("allauth.urls")),
path("register/", RegisterView.as_view(), name="register"),
path("change-password/", ChangePasswordView.as_view(), name="change-password"),
+ path(
+ "restore-password/",
+ PasswordResetView.as_view(template_name="authentication/password_reset.html"),
+ name="password_reset",
+ ),
+ path(
+ "restore-password/done/",
+ PasswordResetDoneView.as_view(
+ template_name="authentication/password_reset_done.html"
+ ),
+ name="password_reset_done",
+ ),
+ path(
+ "reset///",
+ PasswordResetConfirmView.as_view(
+ template_name="authentication/password_reset_confirm.html"
+ ),
+ name="password_reset_confirm",
+ ),
+ path(
+ "reset/done/",
+ PasswordResetCompleteView.as_view(
+ template_name="authentication/password_reset_complete.html"
+ ),
+ name="password_reset_complete",
+ ),
]
From 3674a7bc03eba4a1fa5dc285736b3c9b90715451 Mon Sep 17 00:00:00 2001
From: marnunrey2
Date: Thu, 14 Dec 2023 09:46:11 +0100
Subject: [PATCH 02/16] feat: saving changes for reviewing
---
.../templates/authentication/login.html | 2 +-
.../authentication/password_reset.html | 16 +++-
.../authentication/password_reset_done.html | 8 +-
decide/authentication/urls.py | 3 +
decide/authentication/views.py | 80 +++++++++++++++++++
decide/decide/settings.py | 6 ++
requirements.txt | 57 ++++++++++---
7 files changed, 157 insertions(+), 15 deletions(-)
diff --git a/decide/authentication/templates/authentication/login.html b/decide/authentication/templates/authentication/login.html
index 92211b700..70457c46c 100644
--- a/decide/authentication/templates/authentication/login.html
+++ b/decide/authentication/templates/authentication/login.html
@@ -102,7 +102,7 @@
- Recuperar Contraseña
+ Recuperar Contraseña
{% endblock %}
diff --git a/decide/authentication/templates/authentication/password_reset.html b/decide/authentication/templates/authentication/password_reset.html
index fd7813151..d34471c45 100644
--- a/decide/authentication/templates/authentication/password_reset.html
+++ b/decide/authentication/templates/authentication/password_reset.html
@@ -8,7 +8,18 @@
{% endblock %}
{% block content %}
-
+
+ {% else %}
+
+ The password reset link was invalid, possibly because it has already been used
+
+ {% endif %}
+
{% endblock %}
diff --git a/decide/authentication/templates/authentication/password_reset_done.html b/decide/authentication/templates/authentication/password_reset_done.html
index 8ea203fb4..34d60fcfa 100644
--- a/decide/authentication/templates/authentication/password_reset_done.html
+++ b/decide/authentication/templates/authentication/password_reset_done.html
@@ -4,12 +4,20 @@
{% block title %}Restore password{% endblock %}
{% block extrahead %}
-
+
{% endblock %}
{% block content %}
+
+
+
+ Se ha enviado un correo a tu email para resetear la contraseña. Revisa tu correo y sigue las instrucciones.
+
+
+
{% endblock %}
diff --git a/decide/authentication/urls.py b/decide/authentication/urls.py
index 97114d90c..2dd0f49ad 100644
--- a/decide/authentication/urls.py
+++ b/decide/authentication/urls.py
@@ -7,10 +7,12 @@
LogoutView,
RegisterView,
ChangePasswordView,
- ResetPasswordView,
- ResetPasswordDoneView,
- ResetPasswordConfirmView,
- ResetPasswordCompleteView,
+)
+from django.contrib.auth.views import (
+ PasswordResetView,
+ PasswordResetDoneView,
+ PasswordResetCompleteView,
+ PasswordResetConfirmView,
)
urlpatterns = [
@@ -21,20 +23,30 @@
path("accounts/", include("allauth.urls")),
path("register/", RegisterView.as_view(), name="register"),
path("change-password/", ChangePasswordView.as_view(), name="change-password"),
- path("password_reset/", ResetPasswordView.as_view(), name="password_reset"),
path(
- "password_reset/done/",
- ResetPasswordDoneView.as_view(),
+ "password_reset/",
+ PasswordResetView.as_view(template_name="authentication/password_reset.html"),
+ name="password_reset",
+ ),
+ path(
+ "password_reset_done/",
+ PasswordResetDoneView.as_view(
+ template_name="authentication/password_reset_done.html"
+ ),
name="password_reset_done",
),
path(
- "reset///",
- ResetPasswordConfirmView.as_view(),
+ "password_reset_confirm///",
+ PasswordResetConfirmView.as_view(
+ template_name="authentication/password_reset_confirm.html"
+ ),
name="password_reset_confirm",
),
path(
- "reset/done/",
- ResetPasswordCompleteView.as_view(),
+ "password_reset_complete/",
+ PasswordResetCompleteView.as_view(
+ template_name="authentication/password_reset_complete.html"
+ ),
name="password_reset_complete",
),
path("social-auth/", include("social_django.urls", namespace="social_auth")),
diff --git a/decide/authentication/views.py b/decide/authentication/views.py
index c8d850853..0989342bc 100644
--- a/decide/authentication/views.py
+++ b/decide/authentication/views.py
@@ -11,18 +11,10 @@
from .forms import LoginForm, RegisterForm
from .serializers import UserSerializer
-from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
+from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.views import (
PasswordResetView,
- PasswordResetDoneView,
- PasswordResetCompleteView,
- PasswordResetConfirmView,
)
-from sendgrid import SendGridAPIClient
-from sendgrid.helpers.mail import Mail
-from django.contrib.auth.models import User
-from django.contrib.sites.models import Site
-from django.contrib.auth.tokens import PasswordResetTokenGenerator
# Non-api view
@@ -98,87 +90,8 @@ class ChangePasswordView(PasswordChangeView):
class ResetPasswordView(PasswordResetView):
template_name = "authentication/password_reset.html"
- success_url = "/password_reset/done/"
def post(self, request):
form = PasswordResetForm(request.POST)
- if form.is_valid():
- email = form.cleaned_data.get("email")
- mailMessage = Mail(
- from_email="decidezambrano@gmail.com",
- to_emails=email,
- )
-
- user = User.objects.get(email=email)
- token = PasswordResetTokenGenerator().make_token(user)
-
- idEncode = f"salt{user.pk}"
- encoded = base64.b64encode(bytes(idEncode, encoding="utf-8")).decode(
- "utf-8"
- )
- urlVerificar = (
- f"{Site.objects.get_current().domain}/reset/{encoded}/{token}/"
- )
-
- mailMessage.dynamic_template_data = {
- "urlVerificar": urlVerificar,
- "user": user.first_name,
- }
- mailMessage.template_id = "d-01c8e3b0691044009b4512599cf77eca"
- try:
- sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))
- sg.send(mailMessage)
- except Exception as e:
- print(e)
-
- return render(
- request, "authentication/password_reset_done.html", {"form": form}
- )
-
- else:
- msg = "No user with that email"
- return render(
- request,
- "authentication/password_reset.html",
- {"form": form, "message": msg},
- )
-
-
-class ResetPasswordDoneView(PasswordResetDoneView):
- template_name = "authentication/password_reset_done.html"
- success_url = "/"
-
-
-class ResetPasswordConfirmView(PasswordResetConfirmView):
- template_name = "authentication/password_reset_confirm.html"
- success_url = "/reset/done/"
-
- def post(self, request):
- form = SetPasswordForm(request.POST)
-
- new_password = request.POST.get("new_password1", None)
- confirm_new_password = request.POST.get("new_password2", None)
- print(new_password)
- print(confirm_new_password)
- if new_password:
- if new_password == confirm_new_password:
- request.user.set_password(new_password)
- request.user.save()
- return render(
- request,
- "authentication/password_reset_complete.html",
- {"form": form},
- )
- else:
- msg = "Las contraseñas no coinciden."
- return render(
- request,
- "authentication/password_reset_complete.html",
- {"form": form, "message": msg},
- )
-
-
-class ResetPasswordCompleteView(PasswordResetCompleteView):
- template_name = "authentication/password_reset_complete.html"
- success_url = "/"
+ ## TODO: Check that email is in database before sending to user
diff --git a/decide/decide/settings.py b/decide/decide/settings.py
index 0e16c6712..0fbe6eff0 100644
--- a/decide/decide/settings.py
+++ b/decide/decide/settings.py
@@ -205,8 +205,13 @@
# Restore password
-EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
-EMAIL_FILE_PATH = BASE_DIR + "/sent_emails"
+EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
+EMAIL_HOST = "smtp.gmail.com"
+EMAIL_PORT = 587
+EMAIL_USE_TLS = True
+EMAIL_HOST_USER = "decidezambrano@gmail.com"
+EMAIL_HOST_PASSWORD = "yhgl cbmn baaj ppzs"
+
try:
from local_settings import *
From 680cd49d55675851ad1c9540cac34613a6cc72b8 Mon Sep 17 00:00:00 2001
From: marnunrey2
Date: Mon, 18 Dec 2023 14:10:41 +0100
Subject: [PATCH 07/16] feat: check email in database
---
.../authentication/password_reset.html | 7 +++++++
.../authentication/password_reset_confirm.html | 10 +++++++---
decide/authentication/urls.py | 4 ++--
decide/authentication/views.py | 18 +++++++++++-------
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/decide/authentication/templates/authentication/password_reset.html b/decide/authentication/templates/authentication/password_reset.html
index 29a902c77..dc72b0902 100644
--- a/decide/authentication/templates/authentication/password_reset.html
+++ b/decide/authentication/templates/authentication/password_reset.html
@@ -21,6 +21,13 @@
{% endif %}
+ {% if messages %}
+
+ {% endif %}