Repository: translate/pootle

Issue:
With no EMAIL_* users are still able to attempt to register
If no `EMAIL_*` settings are set then password reset will fail with a traceback.  Pootle should not issue a traceback, it should at least report on the admin interface that users can't register/reset passwords because no `EMAIL` is setup (though I thought it did this previously).

Reset password should be disabled if there is no `EMAIL_*` setup.



Discussion:
Does this happen in the allauth branch?

To my understanding having email settings is a hard requirement since otherwise users can't register and there is no way to contact admins, so adding a check that ensures the email settings are configured feels the right approach.

After a second review that actually doesn't fix anything.

Actually ensuring a working server is available we can avoid this situation. See PR #4011.


Resolving patch:
diff --git a/pootle/apps/accounts/adapter.py b/pootle/apps/accounts/adapter.py
--- a/pootle/apps/accounts/adapter.py
+++ b/pootle/apps/accounts/adapter.py
@@ -7,12 +7,18 @@
 # or later license. See the LICENSE file for a copy of the license and the
 # AUTHORS file for copyright and authorship information.
 
+import logging
+
 from django.conf import settings
 from django.http import JsonResponse
+from django.utils.translation import ugettext_lazy as _
 
 from allauth.account.adapter import DefaultAccountAdapter
 
 
+logger = logging.getLogger('action')
+
+
 class PootleAccountAdapter(DefaultAccountAdapter):
     """Reimplementation of DefaultAccountAdapter from allauth to change
     ajax_response.
@@ -47,3 +53,14 @@ def is_open_for_signup(self, request):
     def add_message(self, request, level, message_template, *args, **kwargs):
         """Silence messages altogether."""
         pass
+
+    def send_confirmation_mail(self, *args, **kwargs):
+        try:
+            super(PootleAccountAdapter, self).send_confirmation_mail(*args,
+                                                                     **kwargs)
+        except Exception:
+            logger.exception("ERROR: Sign up failed. Couldn't sent "
+                             "confirmation email.")
+            raise RuntimeError(_('Some problem happened when tried to send '
+                                 'the confirmation email. Please try again '
+                                 'later.'))
diff --git a/pootle/checks.py b/pootle/checks.py
--- a/pootle/checks.py
+++ b/pootle/checks.py
@@ -304,3 +304,26 @@ def check_db_transaction_on_commit(app_configs=None, **kwargs):
             id="pootle.C006",
         ))
     return errors
+
+
+@checks.register()
+def check_email_server_is_alive(app_configs=None, **kwargs):
+    from django.conf import settings
+
+    errors = []
+    if settings.POOTLE_SIGNUP_ENABLED or settings.POOTLE_CONTACT_ENABLED:
+        from django.core.mail import get_connection
+
+        connection = get_connection()
+        try:
+            connection.open()
+        except Exception:
+            errors.append(checks.Warning(
+                _("Email server is not available."),
+                hint=_("Review your email settings and make sure your email "
+                       "server is working."),
+                id="pootle.W004",
+            ))
+        else:
+            connection.close()
+    return errors


Test patch: