prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Password reset sends outdated reset token
  When requesting a password reset link from apps.nextcloud.com, the token in the link of the reset e-mail does not work, the website reports:
  
  >  Bad API Token
  > 
  > The password reset link was invalid, possibly because it has already been used. Please request a new password reset.
  
  When requesting a new password reset, an e-mail with the very same token is sent. In consequence it is impossible to change the password.
  
  ## Details
  
  * Firefox 72.0.2
  
  ## Steps to reproduce
  
  1. "Forget" your password
  2. Request password reset link
  3. Receive e-mail and open reset link
  4. Observe error, follow suggestion and request new link
  5. Receive e-mail with exactly the same token
  
  
  </issue>
  <code>
  [start of nextcloudappstore/user/forms.py]
  1 from allauth.account.utils import filter_users_by_email, user_username, \
  2     user_pk_to_url_str
  3 from django import forms
  4 from django.contrib.auth import get_user_model
  5 from django.forms import EmailField, CharField, PasswordInput
  6 from django.utils.translation import ugettext_lazy as _
  7 from snowpenguin.django.recaptcha2.fields import ReCaptchaField
  8 from snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget
  9 
  10 
  11 class SignupFormRecaptcha(forms.Form):
  12     """integrate a recaptcha field."""
  13     recaptcha = ReCaptchaField(widget=ReCaptchaWidget())
  14     first_name = CharField(max_length=30, label=_('First name'))
  15     last_name = CharField(max_length=30, label=_('Last name'))
  16 
  17     def signup(self, request, user):
  18         user.first_name = self.cleaned_data['first_name']
  19         user.last_name = self.cleaned_data['last_name']
  20         user.save()
  21 
  22 
  23 class DeleteAccountForm(forms.Form):
  24     email = EmailField(required=True, label=_('Your e-mail address'))
  25 
  26     def __init__(self, *args, **kwargs):
  27         self.user = kwargs.pop('user', None)
  28         super().__init__(*args, **kwargs)
  29 
  30     def clean_email(self):
  31         email = self.cleaned_data.get('email')
  32         if self.user and self.user.email == email:
  33             return email
  34         else:
  35             raise forms.ValidationError(_(
  36                 'The given e-mail address does not match your e-mail address'))
  37 
  38 
  39 class AccountForm(forms.ModelForm):
  40     passwd = CharField(widget=PasswordInput(), label=_('Confirm password'),
  41                        help_text=_('Password is required to prevent '
  42                                    'unauthorized users from changing your '
  43                                    'email address and resetting your '
  44                                    'password. This field does not update your '
  45                                    'password!'))
  46 
  47     class Meta:
  48         model = get_user_model()
  49         fields = ('first_name', 'last_name', 'email')
  50 
  51     def clean_email(self):
  52         value = self.cleaned_data['email']
  53         users = filter_users_by_email(value)
  54         if [u for u in users if u.pk != self.instance.pk]:
  55             msg = _(
  56                 'This e-mail address is already associated with another '
  57                 'account.')
  58             raise forms.ValidationError(msg)
  59         return value
  60 
  61     def clean_passwd(self):
  62         value = self.cleaned_data['passwd']
  63         if self.instance.check_password(value):
  64             return value
  65         else:
  66             raise forms.ValidationError(_('Invalid password'))
  67 
  68 
  69 class CustomResetPasswordForm(forms.Form):
  70     # remove this class once issue #1307 is resolved django-allauth
  71     email = forms.EmailField(
  72         label=_("E-mail"),
  73         required=True,
  74         widget=forms.TextInput(attrs={
  75             "type": "email",
  76             "size": "30",
  77             "placeholder": _("E-mail address"),
  78         })
  79     )
  80 
  81     def clean_email(self):
  82         email = self.cleaned_data["email"]
  83         from allauth.account.adapter import get_adapter
  84         email = get_adapter().clean_email(email)
  85         self.users = filter_users_by_email(email)
  86 
  87         return self.cleaned_data["email"]
  88 
  89     def save(self, request, **kwargs):
  90         from django.contrib.sites.shortcuts import get_current_site
  91         current_site = get_current_site(request)
  92         email = self.cleaned_data["email"]
  93         from django.contrib.auth.tokens import default_token_generator
  94         token_generator = kwargs.get("token_generator",
  95                                      default_token_generator)
  96 
  97         for user in self.users:
  98             temp_key = token_generator.make_token(user)
  99 
  100             # save it to the password reset model
  101             # password_reset = PasswordReset(user=user, temp_key=temp_key)
  102             # password_reset.save()
  103 
  104             # send the password reset email
  105             from django.urls import reverse
  106             path = reverse("account_reset_password_from_key",
  107                            kwargs=dict(uidb36=user_pk_to_url_str(user),
  108                                        key=temp_key))
  109             from allauth.utils import build_absolute_uri
  110             url = build_absolute_uri(
  111                 request, path)
  112 
  113             context = {"current_site": current_site,
  114                        "user": user,
  115                        "password_reset_url": url,
  116                        "request": request}
  117 
  118             from allauth.account import app_settings
  119 
  120             if app_settings.AUTHENTICATION_METHOD \
  121                     != app_settings.AuthenticationMethod.EMAIL:
  122                 context['username'] = user_username(user)
  123             from allauth.account.adapter import get_adapter
  124             get_adapter(request).send_mail(
  125                 'account/email/password_reset_key',
  126                 email,
  127                 context)
  128         return self.cleaned_data["email"]
  129
  [end of nextcloudappstore/user/forms.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/nextcloudappstore/user/forms.py b/nextcloudappstore/user/forms.py
  --- a/nextcloudappstore/user/forms.py
  +++ b/nextcloudappstore/user/forms.py
  @@ -1,3 +1,4 @@
  +from allauth.account.forms import EmailAwarePasswordResetTokenGenerator
   from allauth.account.utils import filter_users_by_email, user_username, \
       user_pk_to_url_str
   from django import forms
  @@ -82,7 +83,7 @@
           email = self.cleaned_data["email"]
           from allauth.account.adapter import get_adapter
           email = get_adapter().clean_email(email)
  -        self.users = filter_users_by_email(email)
  +        self.users = filter_users_by_email(email, is_active=True)
   
           return self.cleaned_data["email"]
   
  @@ -90,9 +91,7 @@
           from django.contrib.sites.shortcuts import get_current_site
           current_site = get_current_site(request)
           email = self.cleaned_data["email"]
  -        from django.contrib.auth.tokens import default_token_generator
  -        token_generator = kwargs.get("token_generator",
  -                                     default_token_generator)
  +        token_generator = EmailAwarePasswordResetTokenGenerator()
   
           for user in self.users:
               temp_key = token_generator.make_token(user)
  @@ -118,7 +117,7 @@
               from allauth.account import app_settings
   
               if app_settings.AUTHENTICATION_METHOD \
  -                    != app_settings.AuthenticationMethod.EMAIL:
  +                != app_settings.AuthenticationMethod.EMAIL:
                   context['username'] = user_username(user)
               from allauth.account.adapter import get_adapter
               get_adapter(request).send_mail(
  
verification_info: {"golden_diff": "diff --git a/nextcloudappstore/user/forms.py b/nextcloudappstore/user/forms.py\n--- a/nextcloudappstore/user/forms.py\n+++ b/nextcloudappstore/user/forms.py\n@@ -1,3 +1,4 @@\n+from allauth.account.forms import EmailAwarePasswordResetTokenGenerator\n from allauth.account.utils import filter_users_by_email, user_username, \\\n     user_pk_to_url_str\n from django import forms\n@@ -82,7 +83,7 @@\n         email = self.cleaned_data[\"email\"]\n         from allauth.account.adapter import get_adapter\n         email = get_adapter().clean_email(email)\n-        self.users = filter_users_by_email(email)\n+        self.users = filter_users_by_email(email, is_active=True)\n \n         return self.cleaned_data[\"email\"]\n \n@@ -90,9 +91,7 @@\n         from django.contrib.sites.shortcuts import get_current_site\n         current_site = get_current_site(request)\n         email = self.cleaned_data[\"email\"]\n-        from django.contrib.auth.tokens import default_token_generator\n-        token_generator = kwargs.get(\"token_generator\",\n-                                     default_token_generator)\n+        token_generator = EmailAwarePasswordResetTokenGenerator()\n \n         for user in self.users:\n             temp_key = token_generator.make_token(user)\n@@ -118,7 +117,7 @@\n             from allauth.account import app_settings\n \n             if app_settings.AUTHENTICATION_METHOD \\\n-                    != app_settings.AuthenticationMethod.EMAIL:\n+                != app_settings.AuthenticationMethod.EMAIL:\n                 context['username'] = user_username(user)\n             from allauth.account.adapter import get_adapter\n             get_adapter(request).send_mail(\n", "issue": "Password reset sends outdated reset token\nWhen requesting a password reset link from apps.nextcloud.com, the token in the link of the reset e-mail does not work, the website reports:\r\n\r\n>  Bad API Token\r\n> \r\n> The password reset link was invalid, possibly because it has already been used. Please request a new password reset.\r\n\r\nWhen requesting a new password reset, an e-mail with the very same token is sent. In consequence it is impossible to change the password.\r\n\r\n## Details\r\n\r\n* Firefox 72.0.2\r\n\r\n## Steps to reproduce\r\n\r\n1. \"Forget\" your password\r\n2. Request password reset link\r\n3. Receive e-mail and open reset link\r\n4. Observe error, follow suggestion and request new link\r\n5. Receive e-mail with exactly the same token\r\n\n", "before_files": [{"content": "from allauth.account.utils import filter_users_by_email, user_username, \\\n    user_pk_to_url_str\nfrom django import forms\nfrom django.contrib.auth import get_user_model\nfrom django.forms import EmailField, CharField, PasswordInput\nfrom django.utils.translation import ugettext_lazy as _\nfrom snowpenguin.django.recaptcha2.fields import ReCaptchaField\nfrom snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget\n\n\nclass SignupFormRecaptcha(forms.Form):\n    \"\"\"integrate a recaptcha field.\"\"\"\n    recaptcha = ReCaptchaField(widget=ReCaptchaWidget())\n    first_name = CharField(max_length=30, label=_('First name'))\n    last_name = CharField(max_length=30, label=_('Last name'))\n\n    def signup(self, request, user):\n        user.first_name = self.cleaned_data['first_name']\n        user.last_name = self.cleaned_data['last_name']\n        user.save()\n\n\nclass DeleteAccountForm(forms.Form):\n    email = EmailField(required=True, label=_('Your e-mail address'))\n\n    def __init__(self, *args, **kwargs):\n        self.user = kwargs.pop('user', None)\n        super().__init__(*args, **kwargs)\n\n    def clean_email(self):\n        email = self.cleaned_data.get('email')\n        if self.user and self.user.email == email:\n            return email\n        else:\n            raise forms.ValidationError(_(\n                'The given e-mail address does not match your e-mail address'))\n\n\nclass AccountForm(forms.ModelForm):\n    passwd = CharField(widget=PasswordInput(), label=_('Confirm password'),\n                       help_text=_('Password is required to prevent '\n                                   'unauthorized users from changing your '\n                                   'email address and resetting your '\n                                   'password. This field does not update your '\n                                   'password!'))\n\n    class Meta:\n        model = get_user_model()\n        fields = ('first_name', 'last_name', 'email')\n\n    def clean_email(self):\n        value = self.cleaned_data['email']\n        users = filter_users_by_email(value)\n        if [u for u in users if u.pk != self.instance.pk]:\n            msg = _(\n                'This e-mail address is already associated with another '\n                'account.')\n            raise forms.ValidationError(msg)\n        return value\n\n    def clean_passwd(self):\n        value = self.cleaned_data['passwd']\n        if self.instance.check_password(value):\n            return value\n        else:\n            raise forms.ValidationError(_('Invalid password'))\n\n\nclass CustomResetPasswordForm(forms.Form):\n    # remove this class once issue #1307 is resolved django-allauth\n    email = forms.EmailField(\n        label=_(\"E-mail\"),\n        required=True,\n        widget=forms.TextInput(attrs={\n            \"type\": \"email\",\n            \"size\": \"30\",\n            \"placeholder\": _(\"E-mail address\"),\n        })\n    )\n\n    def clean_email(self):\n        email = self.cleaned_data[\"email\"]\n        from allauth.account.adapter import get_adapter\n        email = get_adapter().clean_email(email)\n        self.users = filter_users_by_email(email)\n\n        return self.cleaned_data[\"email\"]\n\n    def save(self, request, **kwargs):\n        from django.contrib.sites.shortcuts import get_current_site\n        current_site = get_current_site(request)\n        email = self.cleaned_data[\"email\"]\n        from django.contrib.auth.tokens import default_token_generator\n        token_generator = kwargs.get(\"token_generator\",\n                                     default_token_generator)\n\n        for user in self.users:\n            temp_key = token_generator.make_token(user)\n\n            # save it to the password reset model\n            # password_reset = PasswordReset(user=user, temp_key=temp_key)\n            # password_reset.save()\n\n            # send the password reset email\n            from django.urls import reverse\n            path = reverse(\"account_reset_password_from_key\",\n                           kwargs=dict(uidb36=user_pk_to_url_str(user),\n                                       key=temp_key))\n            from allauth.utils import build_absolute_uri\n            url = build_absolute_uri(\n                request, path)\n\n            context = {\"current_site\": current_site,\n                       \"user\": user,\n                       \"password_reset_url\": url,\n                       \"request\": request}\n\n            from allauth.account import app_settings\n\n            if app_settings.AUTHENTICATION_METHOD \\\n                    != app_settings.AuthenticationMethod.EMAIL:\n                context['username'] = user_username(user)\n            from allauth.account.adapter import get_adapter\n            get_adapter(request).send_mail(\n                'account/email/password_reset_key',\n                email,\n                context)\n        return self.cleaned_data[\"email\"]\n", "path": "nextcloudappstore/user/forms.py"}]}