Skip to content

Commit

Permalink
Merge pull request #309 from ZdruzenieSTROM/password_reset
Browse files Browse the repository at this point in the history
Pridaná customizácia pre reset hesla
  • Loading branch information
vgeffer authored Dec 9, 2023
2 parents 2fd1ac9 + e6a56bd commit deb8926
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions templates/account/email/password_reset_key_message.txt
Original file line number Diff line number Diff line change
@@ -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
22 changes: 21 additions & 1 deletion user/serializers.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion user/templatetags/registration_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 1 addition & 0 deletions webstrom/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit deb8926

Please sign in to comment.