Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pridaná customizácia pre reset hesla #309

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading