Repository: liqd/a4-meinberlin

Issue:
TemplateDoesNotExist: account/email/account_already_exists.de.email, account/email/account_already_exists.en.email
Sentry Issue: [MEINBERLIN-DEV-81](https://sentry.liqd.net/organizations/liqd/issues/2951/?referrer=github_integration)

```
TemplateDoesNotExist: account/email/account_already_exists.de.email, account/email/account_already_exists.en.email
(16 additional frame(s) were not displayed)
...
  File "meinberlin/apps/users/adapters.py", line 46, in send_mail
    return UserAccountEmail.send(email, template_name=template_prefix, **context)
  File "adhocracy4/emails/mixins.py", line 38, in send
    return cls().dispatch(object, *args, **kwargs)
  File "adhocracy4/emails/base.py", line 127, in dispatch
    (subject, text, html) = self.render(template, context)
  File "adhocracy4/emails/base.py", line 98, in render
    template = select_template(
  File "django/template/loader.py", line 47, in select_template
    raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
```


Discussion:
When I try to register with an existing email address, I get a 500 for that missing email. So, we need to add it. Wording from allauth is:
https://github.com/pennersr/django-allauth/blob/master/allauth/templates/account/email/account_already_exists_message.txt
@CarolingerSeilchenspringer Can you please give us a wording for mB in English and German?
@fuzzylogic2000 So you get a 500+ an email? User will then still not understand quickly, why he*she gets the 500, right? Still better than nothing and if the template is already there, let's use it. I like the allauth wording, here is the translation: 

Sie erhalten diese E-Mail, weil Sie oder jemand anderes versucht haben, sich für ein Konto mit folgender E-Mail-Adresse anzumelden: {{ email }}
Es existiert jedoch bereits ein Konto mit dieser E-Mail-Adresse.  Falls Sie dies vergessen haben, verwenden Sie bitte das Verfahren "Passwort vergessen", um Ihr Konto wiederherzustellen:
@CarolingerSeilchenspringer No, you don't get the email, it tries to find the template for the email, but that doesn't exist, so the user only sees the 500. Cool, thanks for the wording! Will add this to the milestone, then!

And to whoever does this issue: could you check the other templates from allauth (https://github.com/pennersr/django-allauth/tree/master/allauth/templates/account/email), if we all have them in https://github.com/liqd/a4-meinberlin/tree/main/meinberlin/templates/account/email
@khamui If you have time, you could also do this issue! Just ask if you are unsure about how to do it.

Resolving patch:
diff --git a/meinberlin/apps/users/forms.py b/meinberlin/apps/users/forms.py
--- a/meinberlin/apps/users/forms.py
+++ b/meinberlin/apps/users/forms.py
@@ -38,7 +38,6 @@ def clean(self):
         return self.cleaned_data
 
     def clean_username(self):
-
         username = self.cleaned_data["username"]
         try:
             user = User.objects.get(username__iexact=username)
@@ -63,7 +62,6 @@ def clean_username(self):
 
 class AddUserAdminForm(auth_forms.UserCreationForm):
     def clean_username(self):
-
         username = self.cleaned_data["username"]
         user = User.objects.filter(username__iexact=username)
         if user.exists():
@@ -112,10 +110,11 @@ def __init__(self, *args, **kwargs):
 
     def save(self, request):
         user = super(TermsSignupForm, self).save(request)
-        user.get_newsletters = self.cleaned_data["get_newsletters"]
-        user.get_notifications = self.cleaned_data["get_notifications"]
-        user.save()
-        return user
+        if user:
+            user.get_newsletters = self.cleaned_data["get_newsletters"]
+            user.get_notifications = self.cleaned_data["get_notifications"]
+            user.save()
+            return user
 
 
 class SocialTermsSignupForm(SocialSignupForm):


Test patch:
diff --git a/meinberlin/apps/notifications/management/commands/send_test_emails.py b/meinberlin/apps/notifications/management/commands/send_test_emails.py
--- a/meinberlin/apps/notifications/management/commands/send_test_emails.py
+++ b/meinberlin/apps/notifications/management/commands/send_test_emails.py
@@ -79,6 +79,7 @@ def handle(self, *args, **options):
         self._send_allauth_email_confirmation()
         self._send_allauth_password_reset()
         self._send_allauth_unknown_account()
+        self._send_allauth_account_already_exists()
 
     def _send_notifications_create_idea(self):
         # Send notification for a newly created item
@@ -321,6 +322,19 @@ def _send_form_mail(self):
             template_name="meinberlin_cms/emails/form_submission",
         )
 
+    def _send_allauth_account_already_exists(self):
+        context = {
+            "user": self.user,
+            "password_reset_url": "http://example.com/...",
+        }
+
+        TestEmail.send(
+            self.user,
+            receiver=[self.user],
+            template_name="account/email/account_already_exists",
+            **context
+        )
+
     def _send_allauth_password_reset(self):
         context = {
             "user": self.user,