Show friendly infobox when user with unverified email tries logging in
Steps to reproduce
- Register
- Try logging in without verifying email.
What happens?
Login requests fail with 500 status code and generic error page.
There's also something like this in server logs:
api_1 | 2021-07-31T04:22:57.940240124Z 2021-07-31 04:22:57,938 django.request ERROR Internal Server Error: /api/v1/users/login
api_1 | 2021-07-31T04:22:57.940268114Z Traceback (most recent call last):
api_1 | 2021-07-31T04:22:57.940272965Z File "/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
api_1 | 2021-07-31T04:22:57.940276728Z response = get_response(request)
api_1 | 2021-07-31T04:22:57.940280086Z File "/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
api_1 | 2021-07-31T04:22:57.940283728Z response = self.process_exception_by_middleware(e, request)
api_1 | 2021-07-31T04:22:57.940287169Z File "/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
api_1 | 2021-07-31T04:22:57.940290726Z response = wrapped_callback(request, *callback_args, **callback_kwargs)
api_1 | 2021-07-31T04:22:57.940294143Z File "/usr/lib/python3.7/contextlib.py", line 74, in inner
api_1 | 2021-07-31T04:22:57.940297575Z return func(*args, **kwds)
api_1 | 2021-07-31T04:22:57.940320349Z File "/app/funkwhale_api/users/views.py", line 148, in login
api_1 | 2021-07-31T04:22:57.940324865Z if not serializer.is_valid():
api_1 | 2021-07-31T04:22:57.940328315Z File "/venv/lib/python3.7/site-packages/rest_framework/serializers.py", line 234, in is_valid
api_1 | 2021-07-31T04:22:57.940331868Z self._validated_data = self.run_validation(self.initial_data)
api_1 | 2021-07-31T04:22:57.940335279Z File "/venv/lib/python3.7/site-packages/rest_framework/serializers.py", line 436, in run_validation
api_1 | 2021-07-31T04:22:57.940338811Z value = self.validate(value)
api_1 | 2021-07-31T04:22:57.940342084Z File "/app/funkwhale_api/users/serializers.py", line 279, in validate
api_1 | 2021-07-31T04:22:57.940345505Z user = auth.authenticate(request=self.context.get("request"), **data)
api_1 | 2021-07-31T04:22:57.940349151Z File "/venv/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 72, in authenticate
api_1 | 2021-07-31T04:22:57.940352640Z user = backend.authenticate(request, **credentials)
api_1 | 2021-07-31T04:22:57.940356035Z File "/venv/lib/python3.7/site-packages/allauth/account/auth_backends.py", line 22, in authenticate
api_1 | 2021-07-31T04:22:57.940359525Z ret = self._authenticate_by_email(**credentials)
api_1 | 2021-07-31T04:22:57.940362892Z File "/venv/lib/python3.7/site-packages/allauth/account/auth_backends.py", line 55, in _authenticate_by_email
api_1 | 2021-07-31T04:22:57.940366405Z if self._check_password(user, credentials["password"]):
api_1 | 2021-07-31T04:22:57.940369886Z File "/venv/lib/python3.7/site-packages/allauth/account/auth_backends.py", line 62, in _check_password
api_1 | 2021-07-31T04:22:57.940373332Z ret = self.user_can_authenticate(user)
api_1 | 2021-07-31T04:22:57.940376631Z File "/app/funkwhale_api/users/auth_backends.py", line 48, in user_can_authenticate
api_1 | 2021-07-31T04:22:57.940380109Z raise authentication.UnverifiedEmail(user)
api_1 | 2021-07-31T04:22:57.940384228Z funkwhale_api.common.authentication.UnverifiedEmail: kurwanie
What is expected?
Some cUtE box saying something like "You first need to verify your email address before trying to login".
Context
Funkwhale version(s) affected: 1.1.2