We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Misleading error message when trying to register an account and you already have one
"This CalNet account has already submitted a request for approval. If you believe this is an error, please contact us with your CalNet UID: xxx.”


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ocfweb/account/register.py`
Content:
```
1 import ocflib.account.search as search
2 import ocflib.account.validators as validators
3 import ocflib.misc.validators
4 import ocflib.ucb.directory as directory
5 from Crypto.PublicKey import RSA
6 from django import forms
7 from django.conf import settings
8 from django.core.urlresolvers import reverse
9 from django.forms.forms import NON_FIELD_ERRORS
10 from django.http import HttpResponseRedirect
11 from django.shortcuts import render
12 from ocflib.account.creation import encrypt_password
13 from ocflib.account.creation import NewAccountRequest
14 from ocflib.account.search import user_attrs_ucb
15 from ocflib.account.submission import NewAccountResponse
16 from ocflib.constants import CREATE_PUBLIC_KEY
17 
18 from ocfweb.account.constants import TESTER_CALNET_UIDS
19 from ocfweb.auth import calnet_required
20 from ocfweb.component.celery import celery_app
21 from ocfweb.component.celery import validate_then_create_account
22 from ocfweb.component.forms import Form
23 from ocfweb.component.forms import wrap_validator
24 
25 
26 @calnet_required
27 def request_account(request):
28     calnet_uid = request.session['calnet_uid']
29     status = 'new_request'
30 
31     existing_accounts = search.users_by_calnet_uid(calnet_uid)
32 
33     if existing_accounts and calnet_uid not in TESTER_CALNET_UIDS:
34         return render(
35             request,
36             'account/register/already-has-account.html',
37             {
38                 'calnet_uid': calnet_uid,
39                 'calnet_url': settings.LOGOUT_URL,
40                 'title': 'You already have an account',
41             },
42         )
43 
44     # ensure we can even find them in university LDAP
45     # (alumni etc. might not be readable in LDAP but can still auth via CalNet)
46     if not user_attrs_ucb(calnet_uid):
47         return render(
48             request,
49             'account/register/cant-find-in-ldap.html',
50             {
51                 'calnet_uid': calnet_uid,
52                 'calnet_url': settings.LOGOUT_URL,
53                 'title': 'Unable to read account information',
54             },
55         )
56 
57     real_name = directory.name_by_calnet_uid(calnet_uid)
58 
59     if request.method == 'POST':
60         form = ApproveForm(request.POST)
61         if form.is_valid():
62             req = NewAccountRequest(
63                 user_name=form.cleaned_data['ocf_login_name'],
64                 real_name=real_name,
65                 is_group=False,
66                 calnet_uid=calnet_uid,
67                 callink_oid=None,
68                 email=form.cleaned_data['contact_email'],
69                 encrypted_password=encrypt_password(
70                     form.cleaned_data['password'],
71                     RSA.importKey(CREATE_PUBLIC_KEY),
72                 ),
73                 handle_warnings=NewAccountRequest.WARNINGS_WARN,
74             )
75             if 'warnings-submit' in request.POST:
76                 req = req._replace(
77                     handle_warnings=NewAccountRequest.WARNINGS_SUBMIT,
78                 )
79 
80             task = validate_then_create_account.delay(req)
81             task.wait(timeout=5)
82 
83             if isinstance(task.result, NewAccountResponse):
84                 if task.result.status == NewAccountResponse.REJECTED:
85                     status = 'has_errors'
86                     form._errors[NON_FIELD_ERRORS] = form.error_class(task.result.errors)
87                 elif task.result.status == NewAccountResponse.FLAGGED:
88                     status = 'has_warnings'
89                     form._errors[NON_FIELD_ERRORS] = form.error_class(task.result.errors)
90                 elif task.result.status == NewAccountResponse.PENDING:
91                     return HttpResponseRedirect(reverse('account_pending'))
92                 else:
93                     raise AssertionError('Unexpected state reached')
94             else:
95                 # validation was successful, the account is being created now
96                 request.session['approve_task_id'] = task.result
97                 return HttpResponseRedirect(reverse('wait_for_account'))
98     else:
99         form = ApproveForm()
100 
101     return render(
102         request,
103         'account/register/index.html',
104         {
105             'form': form,
106             'real_name': real_name,
107             'status': status,
108             'title': 'Request an OCF account',
109         },
110     )
111 
112 
113 def wait_for_account(request):
114     if 'approve_task_id' not in request.session:
115         return render(
116             request,
117             'account/register/wait/error-no-task-id.html',
118             {'title': 'Account request error'},
119         )
120 
121     task = celery_app.AsyncResult(request.session['approve_task_id'])
122     if not task.ready():
123         meta = task.info
124         status = ['Starting creation']
125         if isinstance(meta, dict) and 'status' in meta:
126             status.extend(meta['status'])
127         return render(
128             request,
129             'account/register/wait/wait.html',
130             {
131                 'title': 'Creating account...',
132                 'status': status,
133             },
134         )
135     elif isinstance(task.result, NewAccountResponse):
136         if task.result.status == NewAccountResponse.CREATED:
137             return HttpResponseRedirect(reverse('account_created'))
138     elif isinstance(task.result, Exception):
139         raise task.result
140 
141     return render(request, 'account/register/wait/error-probably-not-created.html', {})
142 
143 
144 def account_pending(request):
145     return render(request, 'account/register/pending.html', {'title': 'Account request pending'})
146 
147 
148 def account_created(request):
149     return render(request, 'account/register/success.html', {'title': 'Account request successful'})
150 
151 
152 class ApproveForm(Form):
153 
154     ocf_login_name = forms.CharField(
155         label='OCF account name',
156         widget=forms.TextInput(attrs={'placeholder': 'jsmith'}),
157         validators=[wrap_validator(validators.validate_username)],
158         min_length=3,
159         max_length=16,
160     )
161 
162     # password is validated in clean since we need the username as part of the
163     # password validation (to compare similarity)
164     password = forms.CharField(
165         widget=forms.PasswordInput(render_value=True),
166         label='Password',
167         min_length=8,
168         max_length=256,
169     )
170 
171     verify_password = forms.CharField(
172         widget=forms.PasswordInput(render_value=True),
173         label='Confirm password',
174         min_length=8,
175         max_length=64,
176     )
177 
178     contact_email = forms.EmailField(
179         label='Contact e-mail',
180         validators=[wrap_validator(ocflib.misc.validators.valid_email)],
181         widget=forms.EmailInput(attrs={'placeholder': 'jsmith@berkeley.edu'}),
182     )
183 
184     verify_contact_email = forms.EmailField(
185         label='Confirm contact e-mail',
186         widget=forms.EmailInput(attrs={'placeholder': 'jsmith@berkeley.edu'}),
187     )
188 
189     disclaimer_agreement = forms.BooleanField(
190         label='I agree with the above statement.',
191         error_messages={
192             'required': 'You must agree to our policies.'
193         })
194 
195     def clean_verify_password(self):
196         password = self.cleaned_data.get('password')
197         verify_password = self.cleaned_data.get('verify_password')
198 
199         if password and verify_password:
200             if password != verify_password:
201                 raise forms.ValidationError("Your passwords don't match.")
202         return verify_password
203 
204     def clean_verify_contact_email(self):
205         email = self.cleaned_data.get('contact_email')
206         verify_contact_email = self.cleaned_data.get('verify_contact_email')
207 
208         if email and verify_contact_email:
209             if email != verify_contact_email:
210                 raise forms.ValidationError("Your emails don't match.")
211         return verify_contact_email
212 
213     def clean(self):
214         cleaned_data = super(ApproveForm, self).clean()
215 
216         # validate password (requires username to check similarity)
217         username = cleaned_data.get('username')
218         password = cleaned_data.get('password')
219 
220         if username and password:
221             wrap_validator(validators.validate_password)(username, password)
222
```
--- 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/ocfweb/account/register.py b/ocfweb/account/register.py
--- a/ocfweb/account/register.py
+++ b/ocfweb/account/register.py
@@ -35,6 +35,7 @@
             request,
             'account/register/already-has-account.html',
             {
+                'account': ', '.join(existing_accounts),
                 'calnet_uid': calnet_uid,
                 'calnet_url': settings.LOGOUT_URL,
                 'title': 'You already have an account',

{"golden_diff": "diff --git a/ocfweb/account/register.py b/ocfweb/account/register.py\n--- a/ocfweb/account/register.py\n+++ b/ocfweb/account/register.py\n@@ -35,6 +35,7 @@\n             request,\n             'account/register/already-has-account.html',\n             {\n+                'account': ', '.join(existing_accounts),\n                 'calnet_uid': calnet_uid,\n                 'calnet_url': settings.LOGOUT_URL,\n                 'title': 'You already have an account',\n", "issue": "Misleading error message when trying to register an account and you already have one\n\"This CalNet account has already submitted a request for approval. If you believe this is an error, please contact us with your CalNet UID: xxx.\u201d\n\n", "before_files": [{"content": "import ocflib.account.search as search\nimport ocflib.account.validators as validators\nimport ocflib.misc.validators\nimport ocflib.ucb.directory as directory\nfrom Crypto.PublicKey import RSA\nfrom django import forms\nfrom django.conf import settings\nfrom django.core.urlresolvers import reverse\nfrom django.forms.forms import NON_FIELD_ERRORS\nfrom django.http import HttpResponseRedirect\nfrom django.shortcuts import render\nfrom ocflib.account.creation import encrypt_password\nfrom ocflib.account.creation import NewAccountRequest\nfrom ocflib.account.search import user_attrs_ucb\nfrom ocflib.account.submission import NewAccountResponse\nfrom ocflib.constants import CREATE_PUBLIC_KEY\n\nfrom ocfweb.account.constants import TESTER_CALNET_UIDS\nfrom ocfweb.auth import calnet_required\nfrom ocfweb.component.celery import celery_app\nfrom ocfweb.component.celery import validate_then_create_account\nfrom ocfweb.component.forms import Form\nfrom ocfweb.component.forms import wrap_validator\n\n\n@calnet_required\ndef request_account(request):\n    calnet_uid = request.session['calnet_uid']\n    status = 'new_request'\n\n    existing_accounts = search.users_by_calnet_uid(calnet_uid)\n\n    if existing_accounts and calnet_uid not in TESTER_CALNET_UIDS:\n        return render(\n            request,\n            'account/register/already-has-account.html',\n            {\n                'calnet_uid': calnet_uid,\n                'calnet_url': settings.LOGOUT_URL,\n                'title': 'You already have an account',\n            },\n        )\n\n    # ensure we can even find them in university LDAP\n    # (alumni etc. might not be readable in LDAP but can still auth via CalNet)\n    if not user_attrs_ucb(calnet_uid):\n        return render(\n            request,\n            'account/register/cant-find-in-ldap.html',\n            {\n                'calnet_uid': calnet_uid,\n                'calnet_url': settings.LOGOUT_URL,\n                'title': 'Unable to read account information',\n            },\n        )\n\n    real_name = directory.name_by_calnet_uid(calnet_uid)\n\n    if request.method == 'POST':\n        form = ApproveForm(request.POST)\n        if form.is_valid():\n            req = NewAccountRequest(\n                user_name=form.cleaned_data['ocf_login_name'],\n                real_name=real_name,\n                is_group=False,\n                calnet_uid=calnet_uid,\n                callink_oid=None,\n                email=form.cleaned_data['contact_email'],\n                encrypted_password=encrypt_password(\n                    form.cleaned_data['password'],\n                    RSA.importKey(CREATE_PUBLIC_KEY),\n                ),\n                handle_warnings=NewAccountRequest.WARNINGS_WARN,\n            )\n            if 'warnings-submit' in request.POST:\n                req = req._replace(\n                    handle_warnings=NewAccountRequest.WARNINGS_SUBMIT,\n                )\n\n            task = validate_then_create_account.delay(req)\n            task.wait(timeout=5)\n\n            if isinstance(task.result, NewAccountResponse):\n                if task.result.status == NewAccountResponse.REJECTED:\n                    status = 'has_errors'\n                    form._errors[NON_FIELD_ERRORS] = form.error_class(task.result.errors)\n                elif task.result.status == NewAccountResponse.FLAGGED:\n                    status = 'has_warnings'\n                    form._errors[NON_FIELD_ERRORS] = form.error_class(task.result.errors)\n                elif task.result.status == NewAccountResponse.PENDING:\n                    return HttpResponseRedirect(reverse('account_pending'))\n                else:\n                    raise AssertionError('Unexpected state reached')\n            else:\n                # validation was successful, the account is being created now\n                request.session['approve_task_id'] = task.result\n                return HttpResponseRedirect(reverse('wait_for_account'))\n    else:\n        form = ApproveForm()\n\n    return render(\n        request,\n        'account/register/index.html',\n        {\n            'form': form,\n            'real_name': real_name,\n            'status': status,\n            'title': 'Request an OCF account',\n        },\n    )\n\n\ndef wait_for_account(request):\n    if 'approve_task_id' not in request.session:\n        return render(\n            request,\n            'account/register/wait/error-no-task-id.html',\n            {'title': 'Account request error'},\n        )\n\n    task = celery_app.AsyncResult(request.session['approve_task_id'])\n    if not task.ready():\n        meta = task.info\n        status = ['Starting creation']\n        if isinstance(meta, dict) and 'status' in meta:\n            status.extend(meta['status'])\n        return render(\n            request,\n            'account/register/wait/wait.html',\n            {\n                'title': 'Creating account...',\n                'status': status,\n            },\n        )\n    elif isinstance(task.result, NewAccountResponse):\n        if task.result.status == NewAccountResponse.CREATED:\n            return HttpResponseRedirect(reverse('account_created'))\n    elif isinstance(task.result, Exception):\n        raise task.result\n\n    return render(request, 'account/register/wait/error-probably-not-created.html', {})\n\n\ndef account_pending(request):\n    return render(request, 'account/register/pending.html', {'title': 'Account request pending'})\n\n\ndef account_created(request):\n    return render(request, 'account/register/success.html', {'title': 'Account request successful'})\n\n\nclass ApproveForm(Form):\n\n    ocf_login_name = forms.CharField(\n        label='OCF account name',\n        widget=forms.TextInput(attrs={'placeholder': 'jsmith'}),\n        validators=[wrap_validator(validators.validate_username)],\n        min_length=3,\n        max_length=16,\n    )\n\n    # password is validated in clean since we need the username as part of the\n    # password validation (to compare similarity)\n    password = forms.CharField(\n        widget=forms.PasswordInput(render_value=True),\n        label='Password',\n        min_length=8,\n        max_length=256,\n    )\n\n    verify_password = forms.CharField(\n        widget=forms.PasswordInput(render_value=True),\n        label='Confirm password',\n        min_length=8,\n        max_length=64,\n    )\n\n    contact_email = forms.EmailField(\n        label='Contact e-mail',\n        validators=[wrap_validator(ocflib.misc.validators.valid_email)],\n        widget=forms.EmailInput(attrs={'placeholder': 'jsmith@berkeley.edu'}),\n    )\n\n    verify_contact_email = forms.EmailField(\n        label='Confirm contact e-mail',\n        widget=forms.EmailInput(attrs={'placeholder': 'jsmith@berkeley.edu'}),\n    )\n\n    disclaimer_agreement = forms.BooleanField(\n        label='I agree with the above statement.',\n        error_messages={\n            'required': 'You must agree to our policies.'\n        })\n\n    def clean_verify_password(self):\n        password = self.cleaned_data.get('password')\n        verify_password = self.cleaned_data.get('verify_password')\n\n        if password and verify_password:\n            if password != verify_password:\n                raise forms.ValidationError(\"Your passwords don't match.\")\n        return verify_password\n\n    def clean_verify_contact_email(self):\n        email = self.cleaned_data.get('contact_email')\n        verify_contact_email = self.cleaned_data.get('verify_contact_email')\n\n        if email and verify_contact_email:\n            if email != verify_contact_email:\n                raise forms.ValidationError(\"Your emails don't match.\")\n        return verify_contact_email\n\n    def clean(self):\n        cleaned_data = super(ApproveForm, self).clean()\n\n        # validate password (requires username to check similarity)\n        username = cleaned_data.get('username')\n        password = cleaned_data.get('password')\n\n        if username and password:\n            wrap_validator(validators.validate_password)(username, password)\n", "path": "ocfweb/account/register.py"}], "after_files": [{"content": "import ocflib.account.search as search\nimport ocflib.account.validators as validators\nimport ocflib.misc.validators\nimport ocflib.ucb.directory as directory\nfrom Crypto.PublicKey import RSA\nfrom django import forms\nfrom django.conf import settings\nfrom django.core.urlresolvers import reverse\nfrom django.forms.forms import NON_FIELD_ERRORS\nfrom django.http import HttpResponseRedirect\nfrom django.shortcuts import render\nfrom ocflib.account.creation import encrypt_password\nfrom ocflib.account.creation import NewAccountRequest\nfrom ocflib.account.search import user_attrs_ucb\nfrom ocflib.account.submission import NewAccountResponse\nfrom ocflib.constants import CREATE_PUBLIC_KEY\n\nfrom ocfweb.account.constants import TESTER_CALNET_UIDS\nfrom ocfweb.auth import calnet_required\nfrom ocfweb.component.celery import celery_app\nfrom ocfweb.component.celery import validate_then_create_account\nfrom ocfweb.component.forms import Form\nfrom ocfweb.component.forms import wrap_validator\n\n\n@calnet_required\ndef request_account(request):\n    calnet_uid = request.session['calnet_uid']\n    status = 'new_request'\n\n    existing_accounts = search.users_by_calnet_uid(calnet_uid)\n\n    if existing_accounts and calnet_uid not in TESTER_CALNET_UIDS:\n        return render(\n            request,\n            'account/register/already-has-account.html',\n            {\n                'account': ', '.join(existing_accounts),\n                'calnet_uid': calnet_uid,\n                'calnet_url': settings.LOGOUT_URL,\n                'title': 'You already have an account',\n            },\n        )\n\n    # ensure we can even find them in university LDAP\n    # (alumni etc. might not be readable in LDAP but can still auth via CalNet)\n    if not user_attrs_ucb(calnet_uid):\n        return render(\n            request,\n            'account/register/cant-find-in-ldap.html',\n            {\n                'calnet_uid': calnet_uid,\n                'calnet_url': settings.LOGOUT_URL,\n                'title': 'Unable to read account information',\n            },\n        )\n\n    real_name = directory.name_by_calnet_uid(calnet_uid)\n\n    if request.method == 'POST':\n        form = ApproveForm(request.POST)\n        if form.is_valid():\n            req = NewAccountRequest(\n                user_name=form.cleaned_data['ocf_login_name'],\n                real_name=real_name,\n                is_group=False,\n                calnet_uid=calnet_uid,\n                callink_oid=None,\n                email=form.cleaned_data['contact_email'],\n                encrypted_password=encrypt_password(\n                    form.cleaned_data['password'],\n                    RSA.importKey(CREATE_PUBLIC_KEY),\n                ),\n                handle_warnings=NewAccountRequest.WARNINGS_WARN,\n            )\n            if 'warnings-submit' in request.POST:\n                req = req._replace(\n                    handle_warnings=NewAccountRequest.WARNINGS_SUBMIT,\n                )\n\n            task = validate_then_create_account.delay(req)\n            task.wait(timeout=5)\n\n            if isinstance(task.result, NewAccountResponse):\n                if task.result.status == NewAccountResponse.REJECTED:\n                    status = 'has_errors'\n                    form._errors[NON_FIELD_ERRORS] = form.error_class(task.result.errors)\n                elif task.result.status == NewAccountResponse.FLAGGED:\n                    status = 'has_warnings'\n                    form._errors[NON_FIELD_ERRORS] = form.error_class(task.result.errors)\n                elif task.result.status == NewAccountResponse.PENDING:\n                    return HttpResponseRedirect(reverse('account_pending'))\n                else:\n                    raise AssertionError('Unexpected state reached')\n            else:\n                # validation was successful, the account is being created now\n                request.session['approve_task_id'] = task.result\n                return HttpResponseRedirect(reverse('wait_for_account'))\n    else:\n        form = ApproveForm()\n\n    return render(\n        request,\n        'account/register/index.html',\n        {\n            'form': form,\n            'real_name': real_name,\n            'status': status,\n            'title': 'Request an OCF account',\n        },\n    )\n\n\ndef wait_for_account(request):\n    if 'approve_task_id' not in request.session:\n        return render(\n            request,\n            'account/register/wait/error-no-task-id.html',\n            {'title': 'Account request error'},\n        )\n\n    task = celery_app.AsyncResult(request.session['approve_task_id'])\n    if not task.ready():\n        meta = task.info\n        status = ['Starting creation']\n        if isinstance(meta, dict) and 'status' in meta:\n            status.extend(meta['status'])\n        return render(\n            request,\n            'account/register/wait/wait.html',\n            {\n                'title': 'Creating account...',\n                'status': status,\n            },\n        )\n    elif isinstance(task.result, NewAccountResponse):\n        if task.result.status == NewAccountResponse.CREATED:\n            return HttpResponseRedirect(reverse('account_created'))\n    elif isinstance(task.result, Exception):\n        raise task.result\n\n    return render(request, 'account/register/wait/error-probably-not-created.html', {})\n\n\ndef account_pending(request):\n    return render(request, 'account/register/pending.html', {'title': 'Account request pending'})\n\n\ndef account_created(request):\n    return render(request, 'account/register/success.html', {'title': 'Account request successful'})\n\n\nclass ApproveForm(Form):\n\n    ocf_login_name = forms.CharField(\n        label='OCF account name',\n        widget=forms.TextInput(attrs={'placeholder': 'jsmith'}),\n        validators=[wrap_validator(validators.validate_username)],\n        min_length=3,\n        max_length=16,\n    )\n\n    # password is validated in clean since we need the username as part of the\n    # password validation (to compare similarity)\n    password = forms.CharField(\n        widget=forms.PasswordInput(render_value=True),\n        label='Password',\n        min_length=8,\n        max_length=256,\n    )\n\n    verify_password = forms.CharField(\n        widget=forms.PasswordInput(render_value=True),\n        label='Confirm password',\n        min_length=8,\n        max_length=64,\n    )\n\n    contact_email = forms.EmailField(\n        label='Contact e-mail',\n        validators=[wrap_validator(ocflib.misc.validators.valid_email)],\n        widget=forms.EmailInput(attrs={'placeholder': 'jsmith@berkeley.edu'}),\n    )\n\n    verify_contact_email = forms.EmailField(\n        label='Confirm contact e-mail',\n        widget=forms.EmailInput(attrs={'placeholder': 'jsmith@berkeley.edu'}),\n    )\n\n    disclaimer_agreement = forms.BooleanField(\n        label='I agree with the above statement.',\n        error_messages={\n            'required': 'You must agree to our policies.'\n        })\n\n    def clean_verify_password(self):\n        password = self.cleaned_data.get('password')\n        verify_password = self.cleaned_data.get('verify_password')\n\n        if password and verify_password:\n            if password != verify_password:\n                raise forms.ValidationError(\"Your passwords don't match.\")\n        return verify_password\n\n    def clean_verify_contact_email(self):\n        email = self.cleaned_data.get('contact_email')\n        verify_contact_email = self.cleaned_data.get('verify_contact_email')\n\n        if email and verify_contact_email:\n            if email != verify_contact_email:\n                raise forms.ValidationError(\"Your emails don't match.\")\n        return verify_contact_email\n\n    def clean(self):\n        cleaned_data = super(ApproveForm, self).clean()\n\n        # validate password (requires username to check similarity)\n        username = cleaned_data.get('username')\n        password = cleaned_data.get('password')\n\n        if username and password:\n            wrap_validator(validators.validate_password)(username, password)\n", "path": "ocfweb/account/register.py"}]}