GeoNode / geonode

GeoNode is an open source platform that facilitates the creation, sharing, and collaborative use of geospatial data.
https://geonode.org/
Other
1.41k stars 1.11k forks source link

Make user registration more robust #12358

Open etj opened 1 week ago

etj commented 1 week ago

Got an error lately on stable demo that prevented proper user registration. The SMTP SSL certificate was no longer valid, and it broke the registration procedures:

GeoNode log ``` [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'smtp.geo-solutions.it'. (_ssl.c:1007) Traceback (most recent call last): File "/usr/src/geonode/geonode/people/adapters.py", line 170, in send_mail msg.send() File "/usr/local/lib/python3.10/dist-packages/django/core/mail/message.py", line 298, in send return self.get_connection(fail_silently).send_messages([self]) File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 127, in send_messages new_conn_created = self.open() File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 92, in open self.connection.starttls(context=self.ssl_context) File "/usr/lib/python3.10/smtplib.py", line 790, in starttls self.sock = context.wrap_socket(self.sock, File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket return self.sslsocket_class._create( File "/usr/lib/python3.10/ssl.py", line 1100, in _create self.do_handshake() File "/usr/lib/python3.10/ssl.py", line 1371, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'smtp.geo-solutions.it'. (_ssl.c:1007) Traceback (most recent call last): File "/usr/src/geonode/geonode/people/adapters.py", line 170, in send_mail msg.send() File "/usr/local/lib/python3.10/dist-packages/django/core/mail/message.py", line 298, in send return self.get_connection(fail_silently).send_messages([self]) File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 127, in send_messages new_conn_created = self.open() File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 92, in open self.connection.starttls(context=self.ssl_context) File "/usr/lib/python3.10/smtplib.py", line 790, in starttls self.sock = context.wrap_socket(self.sock, File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket return self.sslsocket_class._create( File "/usr/lib/python3.10/ssl.py", line 1100, in _create self.do_handshake() File "/usr/lib/python3.10/ssl.py", line 1371, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'smtp.geo-solutions.it'. (_ssl.c:1007) uring handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/django/contrib/messages/api.py", line 27, in add_message messages = request._messages AttributeError: 'NoneType' object has no attribute '_messages' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.10/dist-packages/django/views/generic/base.py", line 104, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/utils/decorators.py", line 46, in _wrapper return bound_method(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/allauth/decorators.py", line 12, in wrap resp = function(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/utils/decorators.py", line 46, in _wrapper return bound_method(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/views/decorators/debug.py", line 92, in sensitive_post_parameters_wrapper return view(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/utils/decorators.py", line 46, in _wrapper return bound_method(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func response = view_func(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/allauth/account/views.py", line 255, in dispatch return super(SignupView, self).dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/allauth/account/views.py", line 95, in dispatch response = super(RedirectAuthenticatedUserMixin, self).dispatch( File "/usr/local/lib/python3.10/dist-packages/allauth/account/views.py", line 227, in dispatch return super(CloseableSignupMixin, self).dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/views/generic/base.py", line 143, in dispatch return handler(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/allauth/account/views.py", line 123, in post response = self.form_valid(form) File "/usr/local/lib/python3.10/dist-packages/allauth/account/views.py", line 273, in form_valid return complete_signup( File "/usr/local/lib/python3.10/dist-packages/allauth/account/utils.py", line 241, in complete_signup return perform_login( File "/usr/local/lib/python3.10/dist-packages/allauth/account/utils.py", line 166, in perform_login return _perform_login(request, login) File "/usr/local/lib/python3.10/dist-packages/allauth/account/utils.py", line 176, in _perform_login response = adapter.pre_login(request, login.user, **hook_kwargs) File "/usr/src/geonode/geonode/people/adapters.py", line 133, in pre_login return super().pre_login( File "/usr/local/lib/python3.10/dist-packages/allauth/account/adapter.py", line 464, in pre_login send_email_confirmation(request, user, signup=signup, email=email) File "/usr/local/lib/python3.10/dist-packages/allauth/account/utils.py", line 399, in send_email_confirmation email_address.send_confirmation(request, signup=signup) File "/usr/local/lib/python3.10/dist-packages/allauth/account/models.py", line 93, in send_confirmation confirmation.send(request, signup=signup) File "/usr/local/lib/python3.10/dist-packages/allauth/account/models.py", line 126, in send get_adapter().send_confirmation_mail(request, self, signup) File "/usr/local/lib/python3.10/dist-packages/allauth/account/adapter.py", line 641, in send_confirmation_mail self.send_mail(email_template, emailconfirmation.email_address.email, ctx) File "/usr/src/geonode/geonode/people/adapters.py", line 173, in send_mail messages.warning(context.get("request"), f"An error occurred while trying to send the email: {e}") File "/usr/local/lib/python3.10/dist-packages/django/contrib/messages/api.py", line 110, in warning add_message( File "/usr/local/lib/python3.10/dist-packages/django/contrib/messages/api.py", line 30, in add_message raise TypeError( TypeError: add_message() argument must be an HttpRequest object, not 'NoneType'. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/usr/src/geonode_demo/./geonode_demo/middleware.py", line 24, in __call__ response = self.get_response(request) File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 57, in inner response = response_for_exception(request, exc) File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 140, in response_for_exception response = handle_uncaught_exception( File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 185, in handle_uncaught_exception return callback(request) File "/usr/local/lib/python3.10/dist-packages/django/utils/decorators.py", line 134, in _wrapper_view response = view_func(request, *args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/views/defaults.py", line 99, in server_error return HttpResponseServerError(template.render()) File "/usr/local/lib/python3.10/dist-packages/django/template/backends/django.py", line 61, in render return self.template.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 175, in render return self._render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/defaulttags.py", line 321, in render return nodelist.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/usr/local/lib/python3.10/dist-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/usr/local/lib/python3.10/dist-packages/django/template/library.py", line 237, in render output = self.func(*resolved_args, **resolved_kwargs) File "/usr/local/lib/python3.10/dist-packages/allauth/socialaccount/templatetags/socialaccount.py", line 77, in get_providers request = context["request"] File "/usr/local/lib/python3.10/dist-packages/django/template/context.py", line 83, in __getitem__ raise KeyError(key) KeyError: 'request' ``` This last block repeated several time

This led to the error page on the client: image

The mail handling should be