From efa4dc874bd6eb52a13374c7877bb77eb4ea7086 Mon Sep 17 00:00:00 2001 From: kovacspe Date: Sat, 9 Dec 2023 16:30:29 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Pridan=C3=A1=20customiz=C3=A1cia=20pre=20re?= =?UTF-8?q?set=20hesla?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/email/password_reset_key_message.txt | 10 ++++++++++ user/serializers.py | 16 +++++++++++++++- user/templatetags/registration_extras.py | 2 +- webstrom/settings.py | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 templates/account/email/password_reset_key_message.txt diff --git a/templates/account/email/password_reset_key_message.txt b/templates/account/email/password_reset_key_message.txt new file mode 100644 index 00000000..7bbdaa75 --- /dev/null +++ b/templates/account/email/password_reset_key_message.txt @@ -0,0 +1,10 @@ +{% load registration_extras %} + +Ahoj, + +tento e-mail ti prišiel, pretože nám prišla žiadosť o zresetovanie hesla k účtu priradenému k tvojmu e-mailu na stránke strom.sk. Ak si nepraješ zmeniť heslo, tak tento e-mail môžeš ignorovať. + +Ak chceš zresetovať heslo, klikni na tento link: +{{password_reset_url}} + +Tvoji vedúci Stromu \ No newline at end of file diff --git a/user/serializers.py b/user/serializers.py index f6f65fb7..1e8db1aa 100644 --- a/user/serializers.py +++ b/user/serializers.py @@ -1,6 +1,7 @@ from allauth.account.adapter import get_adapter from allauth.account.models import EmailAddress -from allauth.account.utils import setup_user_email +from allauth.account.utils import setup_user_email, user_pk_to_url_str +from dj_rest_auth.serializers import PasswordResetSerializer from django.contrib.auth import authenticate, get_user_model from django.core.mail import send_mail from django.template.loader import render_to_string @@ -14,6 +15,19 @@ from webstrom.settings import EMAIL_ALERT, EMAIL_NO_REPLY +def reset_password_url_generator(request, user, temp_key): + uid = user_pk_to_url_str(user) + host = request.META.get('HTTP_X_FORWARDED_HOST', 'localhost:3000') + return f'{request.scheme}://{host}/strom/reset-password/{temp_key}/{uid}' + + +class FrontendPasswordResetSerializer(PasswordResetSerializer): + def get_email_options(self): + return { + 'url_generator': reset_password_url_generator + } + + @ts_interface(context='user') class LoginSerializer(serializers.Serializer): # pylint: disable=W0223 diff --git a/user/templatetags/registration_extras.py b/user/templatetags/registration_extras.py index 02574425..e291a26d 100644 --- a/user/templatetags/registration_extras.py +++ b/user/templatetags/registration_extras.py @@ -11,4 +11,4 @@ def seminar(request: HttpRequest) -> str: @register.filter def source_host(request: HttpRequest) -> str: - return request.META['HTTP_X_FORWARDED_HOST'] + return request.META.get('HTTP_X_FORWARDED_HOST', 'localhost:3000') diff --git a/webstrom/settings.py b/webstrom/settings.py index fa48fe09..70296ba0 100644 --- a/webstrom/settings.py +++ b/webstrom/settings.py @@ -147,6 +147,7 @@ REST_AUTH = { 'LOGIN_SERIALIZER': 'user.serializers.LoginSerializer', 'USER_DETAILS_SERIALIZER': 'user.serializers.UserDetailsSerializer', + 'PASSWORD_RESET_SERIALIZER': 'user.serializers.FrontendPasswordResetSerializer', 'REGISTER_SERIALIZER': 'user.serializers.RegisterSerializer', 'OLD_PASSWORD_FIELD_ENABLED': True, } From e6a56bd43e2acb4991f3e9238132b4d7342dd413 Mon Sep 17 00:00:00 2001 From: kovacspe Date: Sat, 9 Dec 2023 17:02:39 +0100 Subject: [PATCH 2/2] Redifine abstract --- user/serializers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/user/serializers.py b/user/serializers.py index 1e8db1aa..e01697fb 100644 --- a/user/serializers.py +++ b/user/serializers.py @@ -27,6 +27,12 @@ def get_email_options(self): 'url_generator': reset_password_url_generator } + def create(self, validated_data): + pass + + def update(self, instance, validated_data): + pass + @ts_interface(context='user') class LoginSerializer(serializers.Serializer):