diff --git a/procollab/settings.py b/procollab/settings.py index 1c8568a0..7d57f687 100644 --- a/procollab/settings.py +++ b/procollab/settings.py @@ -73,7 +73,6 @@ "django.contrib.messages", "django.contrib.staticfiles", "debug_toolbar", - "django_rest_passwordreset", # My apps "core.apps.CoreConfig", "industries.apps.IndustriesConfig", @@ -92,6 +91,7 @@ "rest_framework_simplejwt", "rest_framework_simplejwt.token_blacklist", "django_cleanup.apps.CleanupConfig", + "django_rest_passwordreset", # "rest_framework.authtoken", # Plugins "corsheaders", diff --git a/templates/email/password_reset_email.html b/templates/email/password_reset_email.html new file mode 100644 index 00000000..44d3dd26 --- /dev/null +++ b/templates/email/password_reset_email.html @@ -0,0 +1,462 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
Ваш аккаунт верифицирован
+ + +
+ + + + + + + +
+ + + + + +
+ + + + + + + +
+ + + +
+ + + + + + + +
+ + +
+ + + + + + + + + +
+ + + + + + + +
+ + + +
+ +
+ +
+ + +
+ +
+ + + + + +
+ + + + + + + +
+ + + +
+ + + + + + + +
+ + +
+ + + + + + + + + +
+ +
С возвращением, {{ user.first_name }} 👋
+ +
+ +
+ + +
+ +
+ + + + + +
+ + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + +
+ +
Ты можешь сбросить пароль, перейдя по ссылке ниже.
+ +
+ +
+ + + + + + + +
+ + + +
+ +
+ +
+ +
Если ты не запрашивал новый пароль, пожалуйста игнорируй это письмо.
+ +
+ +
+ + +
+ +
+ + + + + +
+ + + + + + + +
+ + +
+ + + + + + + +
+ + + + + + + + + +
+ + + + + + + +
+ + Сбросить пароль + +
+ +
+ +
+ +
+ + +
+ +
+ + + + + +
+ + + + + + + +
+ + +
+ + + + + + + + + +
+ + + +
+ +
+ + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + + + +
+ +
+ + + diff --git a/templates/email/password_reset_email.txt b/templates/email/password_reset_email.txt new file mode 100644 index 00000000..b662c0b8 --- /dev/null +++ b/templates/email/password_reset_email.txt @@ -0,0 +1,3 @@ +С возвращением, {{user.first_name}}! 👋 Ты можешь сбросить пароль, перейдя по ссылке ниже. +Если ты не запрашивал новый пароль, пожалуйста игнорируй это письмо. +{{ reset_password_url }} \ No newline at end of file diff --git a/users/signals.py b/users/signals.py index aae00293..ac7e6471 100644 --- a/users/signals.py +++ b/users/signals.py @@ -1,7 +1,10 @@ +from django.core.mail import EmailMultiAlternatives from django.db.models.signals import post_save from django.dispatch import receiver +from django.template.loader import render_to_string +from django_rest_passwordreset.signals import reset_password_token_created -from users.models import CustomUser, Member, Mentor, Expert, Investor +from users.models import CustomUser, Expert, Investor, Member, Mentor @receiver(post_save, sender=CustomUser) @@ -20,3 +23,27 @@ def create_or_update_user_types(sender, instance, created, **kwargs): if instance.ordering_score != current_ordering_score: instance.ordering_score = current_ordering_score instance.save() + + +@receiver(reset_password_token_created) +def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs): + reset_password_url = ( + f"https://app.procollab.ru/auth/reset_password/?token={reset_password_token.key}" + ) + context = { + "user": reset_password_token.user, + "email": reset_password_token.user.email, + "reset_password_url": reset_password_url, + } + + email_html_message = render_to_string("email/password_reset_email.html", context) + email_plaintext_message = render_to_string("email/password_reset_email.txt", context) + + msg = EmailMultiAlternatives( + "Сброс пароля | Procollab", + email_plaintext_message, + "procollab2022@gmail.com", + [reset_password_token.user.email], + ) + msg.attach_alternative(email_html_message, "text/html") + msg.send() diff --git a/users/urls.py b/users/urls.py index 20a202b7..59408138 100644 --- a/users/urls.py +++ b/users/urls.py @@ -1,4 +1,4 @@ -from django.urls import path, re_path +from django.urls import path, re_path, include from users.views import ( AchievementDetail, @@ -18,8 +18,6 @@ ResendVerifyEmail, CurrentUserPrograms, CurrentUserProgramsTags, - ResetCurrentUserPassword, - EmailResetPassword, ) app_name = "users" @@ -36,7 +34,6 @@ path("users//", UserDetail.as_view()), path("users//set_onboarding_stage/", SetUserOnboardingStage.as_view()), path("users/current/", CurrentUser.as_view()), - path("users/current/email_reset_password/", EmailResetPassword.as_view()), # todo: change password view path("users/current/programs/", CurrentUserPrograms.as_view()), path("users/current/programs/tags/", CurrentUserProgramsTags.as_view()), @@ -59,14 +56,8 @@ VerifyEmail.as_view(), name="account_confirm_email", ), - re_path( - r"^password-reset/", - ResetCurrentUserPassword.as_view(), - name="password_reset_sent", - ), - re_path( - r"^password-reset/(?P[-:\w]+)/$", - ResetCurrentUserPassword.as_view(), - name="password_reset", + path( + "reset_password/", + include("django_rest_passwordreset.urls", namespace="password_reset"), ), ]