Changing email causes UnverifiedEmail exception
Steps to reproduce
- Request email change at settings.
What happens?
Visiting email confirmation page causes Server Error (500) (logs below); Refreshing settings page also causes that error. Logging in after clearing cookies also causes Server Error. The only way to mitigate the issue is to clear cookies and confirm email on clear browser.
What is expected?
User-friendly email change.
Context
Funkwhale version(s) affected: 1.2.3+git.dc35000d
2022-04-20 03:28:32,188 django.request ERROR Internal Server Error: /api/v1/users/login
Traceback (most recent call last):
File "/opt/funkwhale/virtualenv/lib64/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/opt/funkwhale/virtualenv/lib64/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib64/python3.9/contextlib.py", line 79, in inner
return func(*args, **kwds)
File "/opt/funkwhale/api/funkwhale_api/users/views.py", line 148, in login
if not serializer.is_valid():
File "/opt/funkwhale/virtualenv/lib64/python3.9/site-packages/rest_framework/serializers.py", line 220, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/opt/funkwhale/virtualenv/lib64/python3.9/site-packages/rest_framework/serializers.py", line 422, in run_validation
value = self.validate(value)
File "/opt/funkwhale/api/funkwhale_api/users/serializers.py", line 268, in validate
user = auth.authenticate(request=self.context.get("request"), **data)
File "/opt/funkwhale/virtualenv/lib64/python3.9/site-packages/django/views/decorators/debug.py", line 42, in sensitive_variables_wrapper
return func(*func_args, **func_kwargs)
File "/opt/funkwhale/virtualenv/lib64/python3.9/site-packages/django/contrib/auth/__init__.py", line 76, in authenticate
user = backend.authenticate(request, **credentials)
File "/opt/funkwhale/virtualenv/lib64/python3.9/site-packages/django/contrib/auth/backends.py", line 48, in authenticate
if user.check_password(password) and self.user_can_authenticate(user):
File "/opt/funkwhale/api/funkwhale_api/users/auth_backends.py", line 48, in user_can_authenticate
raise authentication.UnverifiedEmail(user)
funkwhale_api.common.authentication.UnverifiedEmail: username