From 81b6078b7ee26e73ec5a09660d1616c4cb025f99 Mon Sep 17 00:00:00 2001 From: wlorenzetti Date: Fri, 10 Nov 2023 08:54:30 +0100 Subject: [PATCH] Refactoring and add settings to reset password and user recovery email templates. --- g3w-admin/base/urls.py | 15 ++++++++------- g3w-admin/usersmanage/views.py | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/g3w-admin/base/urls.py b/g3w-admin/base/urls.py index 131efb7bd..950749d88 100644 --- a/g3w-admin/base/urls.py +++ b/g3w-admin/base/urls.py @@ -22,9 +22,10 @@ G3WRegistrationForm ) from usersmanage.views import ( - UserRegistrationView, - UsernameRecoveryView, - UsernameRecoveryDoneView + G3WUserRegistrationView, + G3WUsernameRecoveryView, + G3WUsernameRecoveryDoneView, + G3WPasswordResetView ) from ajax_select import urls as ajax_select_urls @@ -142,7 +143,7 @@ ), path( "accounts/register/", - UserRegistrationView.as_view( + G3WUserRegistrationView.as_view( extra_context=extra_context_login_page, form_class=G3WRegistrationForm ), @@ -184,7 +185,7 @@ ), path( 'password_reset/', - auth.views.PasswordResetView.as_view( + G3WPasswordResetView.as_view( extra_context=extra_context_login_page, form_class=G3WResetPasswordForm ), @@ -207,14 +208,14 @@ ), path( 'username_recovery/', - UsernameRecoveryView.as_view( + G3WUsernameRecoveryView.as_view( extra_context=extra_context_login_page ), name='username_recovery' ), path( 'username_recovery/done/', - UsernameRecoveryDoneView.as_view(extra_context=extra_context_login_page), + G3WUsernameRecoveryDoneView.as_view(extra_context=extra_context_login_page), name='username_recovery_done' ), ] diff --git a/g3w-admin/usersmanage/views.py b/g3w-admin/usersmanage/views.py index b81ec7317..958905deb 100644 --- a/g3w-admin/usersmanage/views.py +++ b/g3w-admin/usersmanage/views.py @@ -288,7 +288,7 @@ def post(self, *args, **kwargs): 'selected': ug in current_user_groups} for ug in user_groups]}) -class UserRegistrationView(registration_views.RegistrationView): +class G3WUserRegistrationView(registration_views.RegistrationView): """ G3W-ADMIn custom registration view. """ @@ -366,8 +366,23 @@ def send_admin_activation_email(self, user): fail_silently=False, ) +class G3WUserPasswordRecoveryMixin(object): + """ + A mixin to add SITTINGS paramenter inside the template + """ + + extra_email_context = { + 'SETTINGS': settings + } + +class G3WPasswordResetView(G3WUserPasswordRecoveryMixin, PasswordResetView): + """ + Class for G3W-SUITE of PasswordResetView + """ + pass + -class UsernameRecoveryView(PasswordResetView): +class G3WUsernameRecoveryView(G3WUserPasswordRecoveryMixin, PasswordResetView): """ A view to recovery username by email, follow the same logic of Password reset. """ @@ -379,7 +394,7 @@ class UsernameRecoveryView(PasswordResetView): template_name = 'registration/username_recovery_form.html' title = _('Username recovery') -class UsernameRecoveryDoneView(PasswordResetDoneView): +class G3WUsernameRecoveryDoneView(PasswordResetDoneView): """ View for show message to the end user of emailing username. """