+
+
{% trans 'Check your inbox.' %}
+
{% trans "We've emailed you your username. You should receive the email shortly!" %}
+
+
+{% 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 %}
+
+ {% if form.errors %}
+
+ ×
+
{% 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 %}
+
+
+{% 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')