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..e01697fb 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,25 @@ 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 + } + + def create(self, validated_data): + pass + + def update(self, instance, validated_data): + pass + + @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, }