We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `akvo/rest/views/utils.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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)

{"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"}], "after_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__iexact=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"}]}