prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Investigate creation of duplicate user accounts with differently cased emails
  - [ ] Verify that lookups using email are using `__iexact` or something like that. 
  - [ ] Figure out a plan for existing duplicates
  
  </issue>
  <code>
  [start of akvo/rest/views/utils.py]
  1 # -*- coding: utf-8 -*-
  2 
  3 # Akvo RSR is covered by the GNU Affero General Public License.
  4 
  5 # See more details in the license.txt file located at the root folder of the Akvo RSR module.
  6 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
  7 
  8 from django.conf import settings
  9 from django.contrib.auth import get_user_model
  10 from django.core.cache import cache
  11 from django.utils.cache import get_cache_key, _generate_cache_header_key
  12 from django.db import IntegrityError
  13 
  14 
  15 def get_cached_data(request, key_prefix, data, serializer):
  16     """Function to get serialized data from the cache based on the request."""
  17     cache_header_key = _generate_cache_header_key(key_prefix, request)
  18     if cache.get(cache_header_key) is None:
  19         cache.set(cache_header_key, [], None)
  20 
  21     cache_key = get_cache_key(request, key_prefix)
  22     cached_data = cache.get(cache_key, None)
  23     cache_used = True
  24     if not cached_data and data is not None:
  25         cache_used = False
  26         cached_data = serializer(data, many=True).data
  27         cache.set(cache_key, cached_data)
  28 
  29     return cached_data, cache_used
  30 
  31 
  32 def set_cached_data(request, key_prefix, data):
  33     """Function to save data to the cache based on the request."""
  34 
  35     cache_header_key = _generate_cache_header_key(key_prefix, request)
  36     if cache.get(cache_header_key) is None:
  37         cache.set(cache_header_key, [], None)
  38 
  39     cache_key = get_cache_key(request, key_prefix)
  40     cache.set(cache_key, data)
  41 
  42 
  43 def get_qs_elements_for_page(qs, request, count):
  44     """Return queryset elements to be shown on the current page"""
  45     limit = int_or_none(request.GET.get('limit')) or settings.PROJECT_DIRECTORY_PAGE_SIZES[0]
  46     limit = min(limit, settings.PROJECT_DIRECTORY_PAGE_SIZES[-1])
  47     max_page_number = 1 + int(count / limit)
  48     page_number = min(max_page_number, int_or_none(request.GET.get('page')) or 1)
  49     start = (page_number - 1) * limit
  50     end = page_number * limit
  51     return qs[start:end]
  52 
  53 
  54 def int_or_none(value):
  55     """Return int or None given a value."""
  56     try:
  57         return int(value)
  58     except Exception:
  59         return None
  60 
  61 
  62 def create_invited_user(email):
  63     User = get_user_model()
  64     # Check if the user already exists, based on the email address
  65     try:
  66         invited_user = User.objects.get(email=email)
  67     except User.DoesNotExist:
  68         try:
  69             invited_user = User.objects.create_user(username=email, email=email)
  70         except IntegrityError:
  71             return None
  72     return invited_user
  73
  [end of akvo/rest/views/utils.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/akvo/rest/views/utils.py b/akvo/rest/views/utils.py
  --- a/akvo/rest/views/utils.py
  +++ b/akvo/rest/views/utils.py
  @@ -63,7 +63,7 @@
       User = get_user_model()
       # Check if the user already exists, based on the email address
       try:
  -        invited_user = User.objects.get(email=email)
  +        invited_user = User.objects.get(email__iexact=email)
       except User.DoesNotExist:
           try:
               invited_user = User.objects.create_user(username=email, email=email)
  
verification_info: {"golden_diff": "diff --git a/akvo/rest/views/utils.py b/akvo/rest/views/utils.py\n--- a/akvo/rest/views/utils.py\n+++ b/akvo/rest/views/utils.py\n@@ -63,7 +63,7 @@\n     User = get_user_model()\n     # Check if the user already exists, based on the email address\n     try:\n-        invited_user = User.objects.get(email=email)\n+        invited_user = User.objects.get(email__iexact=email)\n     except User.DoesNotExist:\n         try:\n             invited_user = User.objects.create_user(username=email, email=email)\n", "issue": "Investigate creation of duplicate user accounts with differently cased emails\n- [ ] Verify that lookups using email are using `__iexact` or something like that. \n- [ ] Figure out a plan for existing duplicates\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.core.cache import cache\nfrom django.utils.cache import get_cache_key, _generate_cache_header_key\nfrom django.db import IntegrityError\n\n\ndef get_cached_data(request, key_prefix, data, serializer):\n    \"\"\"Function to get serialized data from the cache based on the request.\"\"\"\n    cache_header_key = _generate_cache_header_key(key_prefix, request)\n    if cache.get(cache_header_key) is None:\n        cache.set(cache_header_key, [], None)\n\n    cache_key = get_cache_key(request, key_prefix)\n    cached_data = cache.get(cache_key, None)\n    cache_used = True\n    if not cached_data and data is not None:\n        cache_used = False\n        cached_data = serializer(data, many=True).data\n        cache.set(cache_key, cached_data)\n\n    return cached_data, cache_used\n\n\ndef set_cached_data(request, key_prefix, data):\n    \"\"\"Function to save data to the cache based on the request.\"\"\"\n\n    cache_header_key = _generate_cache_header_key(key_prefix, request)\n    if cache.get(cache_header_key) is None:\n        cache.set(cache_header_key, [], None)\n\n    cache_key = get_cache_key(request, key_prefix)\n    cache.set(cache_key, data)\n\n\ndef get_qs_elements_for_page(qs, request, count):\n    \"\"\"Return queryset elements to be shown on the current page\"\"\"\n    limit = int_or_none(request.GET.get('limit')) or settings.PROJECT_DIRECTORY_PAGE_SIZES[0]\n    limit = min(limit, settings.PROJECT_DIRECTORY_PAGE_SIZES[-1])\n    max_page_number = 1 + int(count / limit)\n    page_number = min(max_page_number, int_or_none(request.GET.get('page')) or 1)\n    start = (page_number - 1) * limit\n    end = page_number * limit\n    return qs[start:end]\n\n\ndef int_or_none(value):\n    \"\"\"Return int or None given a value.\"\"\"\n    try:\n        return int(value)\n    except Exception:\n        return None\n\n\ndef create_invited_user(email):\n    User = get_user_model()\n    # Check if the user already exists, based on the email address\n    try:\n        invited_user = User.objects.get(email=email)\n    except User.DoesNotExist:\n        try:\n            invited_user = User.objects.create_user(username=email, email=email)\n        except IntegrityError:\n            return None\n    return invited_user\n", "path": "akvo/rest/views/utils.py"}]}