diff --git a/g3w-admin/base/urls.py b/g3w-admin/base/urls.py index e7615a6e4..4f6ff7614 100644 --- a/g3w-admin/base/urls.py +++ b/g3w-admin/base/urls.py @@ -21,7 +21,11 @@ G3WResetPasswordForm, G3WRegistrationForm ) -from usersmanage.views import UserRegistrationView +from usersmanage.views import ( + UserRegistrationView, + UsernameRecoveryView, + UsernameRecoveryDoneView +) from ajax_select import urls as ajax_select_urls from sitetree.sitetreeapp import register_i18n_trees @@ -164,6 +168,7 @@ ############################################################# # PASSWORD RESET (user password reset by email) +# USERNAME RECOVERY (username recovery by email) ############################################################# if settings.RESET_USER_PASSWORD: urlpatterns += [ @@ -200,6 +205,18 @@ auth.views.PasswordResetCompleteView.as_view(extra_context=extra_context_login_page), name='password_reset_complete' ), + path( + 'username_recovery/', + UsernameRecoveryView.as_view( + extra_context=extra_context_login_page + ), + name='username_recovery' + ), + path( + 'username_recovery/done/', + UsernameRecoveryDoneView.as_view(extra_context=extra_context_login_page), + name='username_recovery_done' + ), ] ############################################################# diff --git a/g3w-admin/templates/login.html b/g3w-admin/templates/login.html index 47c817c89..e4c2b1839 100644 --- a/g3w-admin/templates/login.html +++ b/g3w-admin/templates/login.html @@ -44,6 +44,18 @@

{% trans 'LOGIN ERROR' %}!

{% trans 'Forgot your password?' %} +
+
+ {% trans 'Forgot your username?' %} +
+
+ {% endif %} + {% if SETTINGS.REGISTRATION_OPEN %} +
+
+ {% trans 'Sign up' %} +
+
{% endif %} {% if SETTINGS.REGISTRATION_OPEN %}
diff --git a/g3w-admin/templates/registration/password_reset_form.html b/g3w-admin/templates/registration/password_reset_form.html index 77abfcc02..5f81d18fc 100644 --- a/g3w-admin/templates/registration/password_reset_form.html +++ b/g3w-admin/templates/registration/password_reset_form.html @@ -8,7 +8,12 @@

{% trans 'LOGIN ERROR' %}!

+ {% if form.errors.email %} {% trans 'Email no present into database' %} + {% endif %} + {% if form.errors.captcha %} + {% trans 'Checking the CAPTCHA is required' %} + {% endif %}
{% endif %}
diff --git a/g3w-admin/templates/registration/username_recovery_done.html b/g3w-admin/templates/registration/username_recovery_done.html new file mode 100644 index 000000000..bd10acdce --- /dev/null +++ b/g3w-admin/templates/registration/username_recovery_done.html @@ -0,0 +1,12 @@ +{% extends "base_login.html" %} +{% load static %} +{% load i18n %} + +{% block login_page_box_body %} + +{% endblock %} \ No newline at end of file diff --git a/g3w-admin/templates/registration/username_recovery_email.html b/g3w-admin/templates/registration/username_recovery_email.html new file mode 100644 index 000000000..60167c146 --- /dev/null +++ b/g3w-admin/templates/registration/username_recovery_email.html @@ -0,0 +1,10 @@ +{% load i18n %}{% autoescape off %} +{% blocktranslate %}You're receiving this email because you requested a username recovery for your user account at {{ site_name }}.{% endblocktranslate %} + +{% translate "Your username is:" %} + +{{ user.get_username }} + +{{ SETTINGS.REGISTRATION_EMAIL_BODY_SIGN }} + +{% endautoescape %} diff --git a/g3w-admin/templates/registration/username_recovery_form.html b/g3w-admin/templates/registration/username_recovery_form.html new file mode 100644 index 000000000..711f48611 --- /dev/null +++ b/g3w-admin/templates/registration/username_recovery_form.html @@ -0,0 +1,37 @@ +{% extends "base_login.html" %} +{% load static %} +{% load i18n %} + +{% block login_page_box_body %} +
+{% endblock %} \ No newline at end of file diff --git a/g3w-admin/templates/registration/username_recovery_subject.txt b/g3w-admin/templates/registration/username_recovery_subject.txt new file mode 100644 index 000000000..f7a634a47 --- /dev/null +++ b/g3w-admin/templates/registration/username_recovery_subject.txt @@ -0,0 +1,3 @@ +{% load i18n %}{% autoescape off %} +{{ SETTINGS.REGISTRATION_EMAIL_SUBJECT_PREFIX}} {% blocktranslate %}Username recovery on {{ site_name }}{% endblocktranslate %} +{% endautoescape %} \ No newline at end of file diff --git a/g3w-admin/usersmanage/forms.py b/g3w-admin/usersmanage/forms.py index f0850fbe8..b341f517b 100644 --- a/g3w-admin/usersmanage/forms.py +++ b/g3w-admin/usersmanage/forms.py @@ -851,7 +851,8 @@ def clean_email(self): - +class G3WUsernameRecoveryForm(G3WreCaptchaFormMixin, PasswordResetForm): + pass diff --git a/g3w-admin/usersmanage/views.py b/g3w-admin/usersmanage/views.py index 56ffefdca..d767994e8 100644 --- a/g3w-admin/usersmanage/views.py +++ b/g3w-admin/usersmanage/views.py @@ -15,6 +15,8 @@ from django.contrib.auth.models import Group from django.contrib.sites.shortcuts import get_current_site from django.template.loader import render_to_string +from django.contrib.auth.views import PasswordResetView, PasswordResetDoneView +from django.urls import reverse_lazy from guardian.shortcuts import assign_perm, get_objects_for_user from guardian.decorators import permission_required_or_403 from django_registration.backends.activation import views as registration_views @@ -335,11 +337,33 @@ def send_admin_activation_email(self, user): request=self.request, ) + # Get email of every admin users (Admin Level 1 and Admin Level 2) + admins = User.objects.filter(is_superuser=True) + send_mail( subject, message, settings.DEFAULT_FROM_EMAIL, - ["to@example.com"], + [a.email for a in admins], fail_silently=False, ) + +class UsernameRecoveryView(PasswordResetView): + """ + A view to recovery username by email, follow the same logic of Password reset. + """ + + email_template_name = 'registration/username_recovery_email.html' + form_class = G3WUsernameRecoveryForm + subject_template_name = 'registration/username_recovery_subject.txt' + success_url = reverse_lazy('username_recovery_done') + template_name = 'registration/username_recovery_form.html' + title = _('Username recovery') + +class UsernameRecoveryDoneView(PasswordResetDoneView): + """ + View for show message to the end user of emailing username. + """ + template_name = 'registration/username_recovery_done.html' + title = _('Username sent')