prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Registering with an existing e-mail creates the user
  When registering:
  
  Choose a username
  Enter an email-adresse already in use.
  The user will be created, and your chosen username will be taken!
  
  Registering with an existing e-mail creates the user
  When registering:
  
  Choose a username
  Enter an email-adresse already in use.
  The user will be created, and your chosen username will be taken!
  
  
  </issue>
  <code>
  [start of apps/authentication/forms.py]
  1 # -*- coding: utf-8 -*-
  2 
  3 import datetime
  4 import re
  5 
  6 from django import forms
  7 from django.contrib import auth
  8 from django.utils.translation import ugettext as _
  9 
  10 from apps.authentication.models import OnlineUser as User
  11 
  12 class LoginForm(forms.Form):
  13     username = forms.CharField(widget=forms.TextInput(), label=_("Brukernavn"), max_length=50)
  14     password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(u"Passord"))
  15     user = None
  16 
  17     def clean(self):
  18         if self._errors:
  19             return
  20     
  21         user = auth.authenticate(username=self.cleaned_data['username'], password=self.cleaned_data['password'])
  22 
  23         if user:
  24             if user.is_active:
  25                 self.user = user
  26             else:
  27                 self._errors['username'] = self.error_class([_(u"Din konto er ikke aktiv. Forsøk gjenoppretning av passord.")])
  28         else:
  29             self._errors['username'] = self.error_class([_(u"Kontoen eksisterer ikke, eller kombinasjonen av brukernavn og passord er feil.")])
  30         return self.cleaned_data
  31 
  32     def login(self, request):
  33         try:
  34             User.objects.get(username=request.POST['username'])
  35         except:
  36             return False
  37         if self.is_valid():
  38             auth.login(request, self.user)
  39             request.session.set_expiry(0)
  40             return True
  41         return False
  42 
  43 class RegisterForm(forms.Form):
  44     username = forms.CharField(label=_("brukernavn"), max_length=20)
  45     first_name = forms.CharField(label=_("fornavn"), max_length=50)
  46     last_name = forms.CharField(label=_("etternavn"), max_length=50)
  47     email = forms.EmailField(label=_("epost"), max_length=50)
  48     password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_("passord"))
  49     repeat_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_("gjenta passord"))
  50     address = forms.CharField(label=_("adresse"), max_length=50)
  51     zip_code = forms.CharField(label=_("postnummer"), max_length=4)
  52     phone = forms.CharField(label=_("telefon"), max_length=20)
  53     
  54     def clean(self):
  55         super(RegisterForm, self).clean()
  56         if self.is_valid():
  57             cleaned_data = self.cleaned_data
  58 
  59             # Check passwords
  60             if cleaned_data['password'] != cleaned_data['repeat_password']:
  61                 self._errors['repeat_password'] = self.error_class([_(u"Passordene er ikke like.")])
  62 
  63             # Check username
  64             username = cleaned_data['username']
  65             if User.objects.filter(username=username).count() > 0:
  66                 self._errors['username'] = self.error_class([_(u"Brukernavnet er allerede registrert.")])
  67             if not re.match("^[a-zA-Z0-9_-]+$", username):
  68                 self._errors['username'] = self.error_class([_(u"Ditt brukernavn inneholdt ulovlige tegn. Lovlige tegn: a-Z 0-9 - _")])
  69 
  70             # Check email
  71             email = cleaned_data['email']
  72             if User.objects.filter(email=email).count() > 0:
  73                 self._errors['email'] = self.error_class([_(u"Det fins allerede en bruker med denne epostadressen.")])
  74 
  75             # ZIP code digits only
  76             zip_code = cleaned_data['zip_code']
  77             if len(zip_code) != 4 or not zip_code.isdigit():
  78                 self._errors['zip_code'] = self.error_class([_(u"Postnummer må bestå av fire siffer.")])
  79 
  80             return cleaned_data 
  81 
  82 class RecoveryForm(forms.Form):
  83     email = forms.EmailField(label="Email", max_length=50)
  84 
  85 class ChangePasswordForm(forms.Form):
  86     new_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(u"nytt passord"))
  87     repeat_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(u"gjenta passord"))
  88 
  89     def clean(self):
  90         super(ChangePasswordForm, self).clean()
  91         if self.is_valid():
  92             cleaned_data = self.cleaned_data
  93 
  94             # Check passwords
  95             if cleaned_data['new_password'] != cleaned_data['repeat_password']:
  96                 self._errors['repeat_password'] = self.error_class([_(u"Passordene er ikke like.")])
  97 
  98             return cleaned_data
  99 
  100 
  101 class NewEmailForm(forms.Form):
  102     new_email = forms.EmailField(_(u"ny epostadresse"))
  103
  [end of apps/authentication/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/apps/authentication/forms.py b/apps/authentication/forms.py
  --- a/apps/authentication/forms.py
  +++ b/apps/authentication/forms.py
  @@ -7,7 +7,7 @@
   from django.contrib import auth
   from django.utils.translation import ugettext as _
   
  -from apps.authentication.models import OnlineUser as User
  +from apps.authentication.models import OnlineUser as User, Email
   
   class LoginForm(forms.Form):
       username = forms.CharField(widget=forms.TextInput(), label=_("Brukernavn"), max_length=50)
  @@ -69,7 +69,7 @@
   
               # Check email
               email = cleaned_data['email']
  -            if User.objects.filter(email=email).count() > 0:
  +            if Email.objects.filter(email=email).count() > 0:
                   self._errors['email'] = self.error_class([_(u"Det fins allerede en bruker med denne epostadressen.")])
   
               # ZIP code digits only
  
verification_info: {"golden_diff": "diff --git a/apps/authentication/forms.py b/apps/authentication/forms.py\n--- a/apps/authentication/forms.py\n+++ b/apps/authentication/forms.py\n@@ -7,7 +7,7 @@\n from django.contrib import auth\n from django.utils.translation import ugettext as _\n \n-from apps.authentication.models import OnlineUser as User\n+from apps.authentication.models import OnlineUser as User, Email\n \n class LoginForm(forms.Form):\n     username = forms.CharField(widget=forms.TextInput(), label=_(\"Brukernavn\"), max_length=50)\n@@ -69,7 +69,7 @@\n \n             # Check email\n             email = cleaned_data['email']\n-            if User.objects.filter(email=email).count() > 0:\n+            if Email.objects.filter(email=email).count() > 0:\n                 self._errors['email'] = self.error_class([_(u\"Det fins allerede en bruker med denne epostadressen.\")])\n \n             # ZIP code digits only\n", "issue": "Registering with an existing e-mail creates the user\nWhen registering:\n\nChoose a username\nEnter an email-adresse already in use.\nThe user will be created, and your chosen username will be taken!\n\nRegistering with an existing e-mail creates the user\nWhen registering:\n\nChoose a username\nEnter an email-adresse already in use.\nThe user will be created, and your chosen username will be taken!\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport datetime\nimport re\n\nfrom django import forms\nfrom django.contrib import auth\nfrom django.utils.translation import ugettext as _\n\nfrom apps.authentication.models import OnlineUser as User\n\nclass LoginForm(forms.Form):\n    username = forms.CharField(widget=forms.TextInput(), label=_(\"Brukernavn\"), max_length=50)\n    password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(u\"Passord\"))\n    user = None\n\n    def clean(self):\n        if self._errors:\n            return\n    \n        user = auth.authenticate(username=self.cleaned_data['username'], password=self.cleaned_data['password'])\n\n        if user:\n            if user.is_active:\n                self.user = user\n            else:\n                self._errors['username'] = self.error_class([_(u\"Din konto er ikke aktiv. Fors\u00f8k gjenoppretning av passord.\")])\n        else:\n            self._errors['username'] = self.error_class([_(u\"Kontoen eksisterer ikke, eller kombinasjonen av brukernavn og passord er feil.\")])\n        return self.cleaned_data\n\n    def login(self, request):\n        try:\n            User.objects.get(username=request.POST['username'])\n        except:\n            return False\n        if self.is_valid():\n            auth.login(request, self.user)\n            request.session.set_expiry(0)\n            return True\n        return False\n\nclass RegisterForm(forms.Form):\n    username = forms.CharField(label=_(\"brukernavn\"), max_length=20)\n    first_name = forms.CharField(label=_(\"fornavn\"), max_length=50)\n    last_name = forms.CharField(label=_(\"etternavn\"), max_length=50)\n    email = forms.EmailField(label=_(\"epost\"), max_length=50)\n    password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(\"passord\"))\n    repeat_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(\"gjenta passord\"))\n    address = forms.CharField(label=_(\"adresse\"), max_length=50)\n    zip_code = forms.CharField(label=_(\"postnummer\"), max_length=4)\n    phone = forms.CharField(label=_(\"telefon\"), max_length=20)\n    \n    def clean(self):\n        super(RegisterForm, self).clean()\n        if self.is_valid():\n            cleaned_data = self.cleaned_data\n\n            # Check passwords\n            if cleaned_data['password'] != cleaned_data['repeat_password']:\n                self._errors['repeat_password'] = self.error_class([_(u\"Passordene er ikke like.\")])\n\n            # Check username\n            username = cleaned_data['username']\n            if User.objects.filter(username=username).count() > 0:\n                self._errors['username'] = self.error_class([_(u\"Brukernavnet er allerede registrert.\")])\n            if not re.match(\"^[a-zA-Z0-9_-]+$\", username):\n                self._errors['username'] = self.error_class([_(u\"Ditt brukernavn inneholdt ulovlige tegn. Lovlige tegn: a-Z 0-9 - _\")])\n\n            # Check email\n            email = cleaned_data['email']\n            if User.objects.filter(email=email).count() > 0:\n                self._errors['email'] = self.error_class([_(u\"Det fins allerede en bruker med denne epostadressen.\")])\n\n            # ZIP code digits only\n            zip_code = cleaned_data['zip_code']\n            if len(zip_code) != 4 or not zip_code.isdigit():\n                self._errors['zip_code'] = self.error_class([_(u\"Postnummer m\u00e5 best\u00e5 av fire siffer.\")])\n\n            return cleaned_data \n\nclass RecoveryForm(forms.Form):\n    email = forms.EmailField(label=\"Email\", max_length=50)\n\nclass ChangePasswordForm(forms.Form):\n    new_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(u\"nytt passord\"))\n    repeat_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_(u\"gjenta passord\"))\n\n    def clean(self):\n        super(ChangePasswordForm, self).clean()\n        if self.is_valid():\n            cleaned_data = self.cleaned_data\n\n            # Check passwords\n            if cleaned_data['new_password'] != cleaned_data['repeat_password']:\n                self._errors['repeat_password'] = self.error_class([_(u\"Passordene er ikke like.\")])\n\n            return cleaned_data\n\n\nclass NewEmailForm(forms.Form):\n    new_email = forms.EmailField(_(u\"ny epostadresse\"))\n", "path": "apps/authentication/forms.py"}]}