We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Access denied on manager login
Currently, after logging in, a manager is redirected to /staff/, but staff mode will not be active, so they will get a 403 access denied.

@janno42 what behavior do we want here? Redirect as if they weren't a manager or enable staff mode?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `evap/evaluation/views.py`
Content:
```
1 import logging
2 from datetime import date, timedelta
3 
4 from django.conf import settings
5 from django.contrib import messages, auth
6 from django.contrib.auth.decorators import login_required
7 from django.core.mail import EmailMessage
8 from django.http import HttpResponse, HttpResponseBadRequest
9 from django.shortcuts import redirect, render
10 from django.utils.translation import gettext as _
11 from django.views.decorators.http import require_POST
12 from django.views.decorators.debug import sensitive_post_parameters
13 from django.views.i18n import set_language
14 
15 from evap.evaluation.forms import NewKeyForm, LoginEmailForm
16 from evap.middleware import no_login_required
17 from evap.evaluation.models import FaqSection, EmailTemplate, Semester
18 
19 logger = logging.getLogger(__name__)
20 
21 
22 def redirect_user_to_start_page(user):
23     # pylint: disable=too-many-return-statements
24     active_semester = Semester.active_semester()
25 
26     if user.is_reviewer:
27         if active_semester is not None:
28             return redirect('staff:semester_view', active_semester.id)
29         return redirect('staff:index')
30 
31     if user.is_grade_publisher:
32         if active_semester is not None:
33             return redirect('grades:semester_view', active_semester.id)
34         return redirect('grades:index')
35 
36     if user.is_student:
37         return redirect('student:index')
38     if user.is_responsible_or_contributor_or_delegate:
39         return redirect('contributor:index')
40 
41     return redirect('results:index')
42 
43 
44 @no_login_required
45 @sensitive_post_parameters("password")
46 def index(request):
47     """Main entry page into EvaP providing all the login options available. The OpenID login is thought to be used for
48        internal users. The login key mechanism is meant to be used to include external participants, e.g. visiting
49        students or visiting contributors. A login with email and password is available if OpenID is deactivated.
50     """
51 
52     # parse the form data into the respective form
53     submit_type = request.POST.get("submit_type", "no_submit")
54     new_key_form = NewKeyForm(request.POST if submit_type == "new_key" else None)
55     login_email_form = LoginEmailForm(request, request.POST if submit_type == "login_email" else None)
56 
57     # process form data
58     if request.method == 'POST':
59         if new_key_form.is_valid():
60             # user wants a new login key
61             profile = new_key_form.get_user()
62             profile.ensure_valid_login_key()
63             profile.save()
64 
65             EmailTemplate.send_login_url_to_user(new_key_form.get_user())
66 
67             messages.success(request, _("We sent you an email with a one-time login URL. Please check your inbox."))
68             return redirect('evaluation:index')
69 
70         if login_email_form.is_valid():
71             # user would like to login with email and password and passed password test
72             auth.login(request, login_email_form.get_user())
73 
74             # clean up our test cookie
75             if request.session.test_cookie_worked():
76                 request.session.delete_test_cookie()
77 
78     # if not logged in by now, render form
79     if not request.user.is_authenticated:
80         # set test cookie to verify whether they work in the next step
81         request.session.set_test_cookie()
82 
83         template_data = dict(
84             new_key_form=new_key_form,
85             login_email_form=login_email_form,
86             openid_active=settings.ACTIVATE_OPEN_ID_LOGIN,
87         )
88         return render(request, "index.html", template_data)
89 
90     # check for redirect variable
91     redirect_to = request.GET.get("next", None)
92     if redirect_to is not None:
93         return redirect(redirect_to)
94 
95     return redirect_user_to_start_page(request.user)
96 
97 
98 @no_login_required
99 def login_key_authentication(request, key):
100     user = auth.authenticate(request, key=key)
101 
102     if user and not user.is_active:
103         messages.error(request, _("Inactive users are not allowed to login."))
104         return redirect('evaluation:index')
105 
106     # If we already have an authenticated user don't try to login a new user. Show an error message if another user
107     # tries to login with a URL in this situation.
108     if request.user.is_authenticated:
109         if user != request.user:
110             messages.error(request, _("Another user is currently logged in. Please logout first and then use the login URL again."))
111         return redirect('evaluation:index')
112 
113     if user and user.login_key_valid_until >= date.today():
114         if request.method != "POST":
115             template_data = {
116                 'username': user.full_name
117             }
118             return render(request, "external_user_confirm_login.html", template_data)
119 
120         # User is valid. Set request.user and persist user in the session by logging the user in.
121         request.user = user
122         auth.login(request, user)
123         messages.success(request, _("Logged in as %s.") % user.full_name)
124         # Invalidate the login key, but keep it stored so we can later identify the user that is trying to login and send a new link
125         user.login_key_valid_until = date.today() - timedelta(1)
126         user.save()
127     elif user:
128         # A user exists, but the login key is not valid anymore. Send the user a new one.
129         user.ensure_valid_login_key()
130         EmailTemplate.send_login_url_to_user(user)
131         messages.warning(request, _("The login URL is not valid anymore. We sent you a new one to your email address."))
132     else:
133         messages.warning(request, _("Invalid login URL. Please request a new one below."))
134 
135     return redirect('evaluation:index')
136 
137 
138 @no_login_required
139 def faq(request):
140     return render(request, "faq.html", dict(sections=FaqSection.objects.all()))
141 
142 
143 @no_login_required
144 def legal_notice(request):
145     return render(request, "legal_notice.html", dict())
146 
147 
148 @require_POST
149 @login_required
150 def contact(request):
151     message = request.POST.get("message")
152     title = request.POST.get("title")
153     email = request.user.email or f"User {request.user.id}"
154     subject = f"[EvaP] Message from {email}"
155 
156     if message:
157         mail = EmailMessage(
158             subject=subject,
159             body="{}\n{}\n\n{}".format(title, request.user.email, message),
160             to=[settings.CONTACT_EMAIL])
161         try:
162             mail.send()
163             logger.info('Sent contact email: \n{}\n'.format(mail.message()))
164             return HttpResponse()
165         except Exception:
166             logger.exception('An exception occurred when sending the following contact email:\n{}\n'.format(mail.message()))
167             raise
168 
169     return HttpResponseBadRequest()
170 
171 
172 @no_login_required
173 @require_POST
174 def set_lang(request):
175     if request.user.is_authenticated:
176         user = request.user
177         user.language = request.POST['language']
178         user.save()
179 
180     return set_language(request)
181
```
--- 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/evap/evaluation/views.py b/evap/evaluation/views.py
--- a/evap/evaluation/views.py
+++ b/evap/evaluation/views.py
@@ -74,6 +74,7 @@
             # clean up our test cookie
             if request.session.test_cookie_worked():
                 request.session.delete_test_cookie()
+            return redirect('evaluation:index')
 
     # if not logged in by now, render form
     if not request.user.is_authenticated:

{"golden_diff": "diff --git a/evap/evaluation/views.py b/evap/evaluation/views.py\n--- a/evap/evaluation/views.py\n+++ b/evap/evaluation/views.py\n@@ -74,6 +74,7 @@\n             # clean up our test cookie\n             if request.session.test_cookie_worked():\n                 request.session.delete_test_cookie()\n+            return redirect('evaluation:index')\n \n     # if not logged in by now, render form\n     if not request.user.is_authenticated:\n", "issue": "Access denied on manager login\nCurrently, after logging in, a manager is redirected to /staff/, but staff mode will not be active, so they will get a 403 access denied.\r\n\r\n@janno42 what behavior do we want here? Redirect as if they weren't a manager or enable staff mode?\n", "before_files": [{"content": "import logging\nfrom datetime import date, timedelta\n\nfrom django.conf import settings\nfrom django.contrib import messages, auth\nfrom django.contrib.auth.decorators import login_required\nfrom django.core.mail import EmailMessage\nfrom django.http import HttpResponse, HttpResponseBadRequest\nfrom django.shortcuts import redirect, render\nfrom django.utils.translation import gettext as _\nfrom django.views.decorators.http import require_POST\nfrom django.views.decorators.debug import sensitive_post_parameters\nfrom django.views.i18n import set_language\n\nfrom evap.evaluation.forms import NewKeyForm, LoginEmailForm\nfrom evap.middleware import no_login_required\nfrom evap.evaluation.models import FaqSection, EmailTemplate, Semester\n\nlogger = logging.getLogger(__name__)\n\n\ndef redirect_user_to_start_page(user):\n    # pylint: disable=too-many-return-statements\n    active_semester = Semester.active_semester()\n\n    if user.is_reviewer:\n        if active_semester is not None:\n            return redirect('staff:semester_view', active_semester.id)\n        return redirect('staff:index')\n\n    if user.is_grade_publisher:\n        if active_semester is not None:\n            return redirect('grades:semester_view', active_semester.id)\n        return redirect('grades:index')\n\n    if user.is_student:\n        return redirect('student:index')\n    if user.is_responsible_or_contributor_or_delegate:\n        return redirect('contributor:index')\n\n    return redirect('results:index')\n\n\n@no_login_required\n@sensitive_post_parameters(\"password\")\ndef index(request):\n    \"\"\"Main entry page into EvaP providing all the login options available. The OpenID login is thought to be used for\n       internal users. The login key mechanism is meant to be used to include external participants, e.g. visiting\n       students or visiting contributors. A login with email and password is available if OpenID is deactivated.\n    \"\"\"\n\n    # parse the form data into the respective form\n    submit_type = request.POST.get(\"submit_type\", \"no_submit\")\n    new_key_form = NewKeyForm(request.POST if submit_type == \"new_key\" else None)\n    login_email_form = LoginEmailForm(request, request.POST if submit_type == \"login_email\" else None)\n\n    # process form data\n    if request.method == 'POST':\n        if new_key_form.is_valid():\n            # user wants a new login key\n            profile = new_key_form.get_user()\n            profile.ensure_valid_login_key()\n            profile.save()\n\n            EmailTemplate.send_login_url_to_user(new_key_form.get_user())\n\n            messages.success(request, _(\"We sent you an email with a one-time login URL. Please check your inbox.\"))\n            return redirect('evaluation:index')\n\n        if login_email_form.is_valid():\n            # user would like to login with email and password and passed password test\n            auth.login(request, login_email_form.get_user())\n\n            # clean up our test cookie\n            if request.session.test_cookie_worked():\n                request.session.delete_test_cookie()\n\n    # if not logged in by now, render form\n    if not request.user.is_authenticated:\n        # set test cookie to verify whether they work in the next step\n        request.session.set_test_cookie()\n\n        template_data = dict(\n            new_key_form=new_key_form,\n            login_email_form=login_email_form,\n            openid_active=settings.ACTIVATE_OPEN_ID_LOGIN,\n        )\n        return render(request, \"index.html\", template_data)\n\n    # check for redirect variable\n    redirect_to = request.GET.get(\"next\", None)\n    if redirect_to is not None:\n        return redirect(redirect_to)\n\n    return redirect_user_to_start_page(request.user)\n\n\n@no_login_required\ndef login_key_authentication(request, key):\n    user = auth.authenticate(request, key=key)\n\n    if user and not user.is_active:\n        messages.error(request, _(\"Inactive users are not allowed to login.\"))\n        return redirect('evaluation:index')\n\n    # If we already have an authenticated user don't try to login a new user. Show an error message if another user\n    # tries to login with a URL in this situation.\n    if request.user.is_authenticated:\n        if user != request.user:\n            messages.error(request, _(\"Another user is currently logged in. Please logout first and then use the login URL again.\"))\n        return redirect('evaluation:index')\n\n    if user and user.login_key_valid_until >= date.today():\n        if request.method != \"POST\":\n            template_data = {\n                'username': user.full_name\n            }\n            return render(request, \"external_user_confirm_login.html\", template_data)\n\n        # User is valid. Set request.user and persist user in the session by logging the user in.\n        request.user = user\n        auth.login(request, user)\n        messages.success(request, _(\"Logged in as %s.\") % user.full_name)\n        # Invalidate the login key, but keep it stored so we can later identify the user that is trying to login and send a new link\n        user.login_key_valid_until = date.today() - timedelta(1)\n        user.save()\n    elif user:\n        # A user exists, but the login key is not valid anymore. Send the user a new one.\n        user.ensure_valid_login_key()\n        EmailTemplate.send_login_url_to_user(user)\n        messages.warning(request, _(\"The login URL is not valid anymore. We sent you a new one to your email address.\"))\n    else:\n        messages.warning(request, _(\"Invalid login URL. Please request a new one below.\"))\n\n    return redirect('evaluation:index')\n\n\n@no_login_required\ndef faq(request):\n    return render(request, \"faq.html\", dict(sections=FaqSection.objects.all()))\n\n\n@no_login_required\ndef legal_notice(request):\n    return render(request, \"legal_notice.html\", dict())\n\n\n@require_POST\n@login_required\ndef contact(request):\n    message = request.POST.get(\"message\")\n    title = request.POST.get(\"title\")\n    email = request.user.email or f\"User {request.user.id}\"\n    subject = f\"[EvaP] Message from {email}\"\n\n    if message:\n        mail = EmailMessage(\n            subject=subject,\n            body=\"{}\\n{}\\n\\n{}\".format(title, request.user.email, message),\n            to=[settings.CONTACT_EMAIL])\n        try:\n            mail.send()\n            logger.info('Sent contact email: \\n{}\\n'.format(mail.message()))\n            return HttpResponse()\n        except Exception:\n            logger.exception('An exception occurred when sending the following contact email:\\n{}\\n'.format(mail.message()))\n            raise\n\n    return HttpResponseBadRequest()\n\n\n@no_login_required\n@require_POST\ndef set_lang(request):\n    if request.user.is_authenticated:\n        user = request.user\n        user.language = request.POST['language']\n        user.save()\n\n    return set_language(request)\n", "path": "evap/evaluation/views.py"}], "after_files": [{"content": "import logging\nfrom datetime import date, timedelta\n\nfrom django.conf import settings\nfrom django.contrib import messages, auth\nfrom django.contrib.auth.decorators import login_required\nfrom django.core.mail import EmailMessage\nfrom django.http import HttpResponse, HttpResponseBadRequest\nfrom django.shortcuts import redirect, render\nfrom django.utils.translation import gettext as _\nfrom django.views.decorators.http import require_POST\nfrom django.views.decorators.debug import sensitive_post_parameters\nfrom django.views.i18n import set_language\n\nfrom evap.evaluation.forms import NewKeyForm, LoginEmailForm\nfrom evap.middleware import no_login_required\nfrom evap.evaluation.models import FaqSection, EmailTemplate, Semester\n\nlogger = logging.getLogger(__name__)\n\n\ndef redirect_user_to_start_page(user):\n    # pylint: disable=too-many-return-statements\n    active_semester = Semester.active_semester()\n\n    if user.is_reviewer:\n        if active_semester is not None:\n            return redirect('staff:semester_view', active_semester.id)\n        return redirect('staff:index')\n\n    if user.is_grade_publisher:\n        if active_semester is not None:\n            return redirect('grades:semester_view', active_semester.id)\n        return redirect('grades:index')\n\n    if user.is_student:\n        return redirect('student:index')\n    if user.is_responsible_or_contributor_or_delegate:\n        return redirect('contributor:index')\n\n    return redirect('results:index')\n\n\n@no_login_required\n@sensitive_post_parameters(\"password\")\ndef index(request):\n    \"\"\"Main entry page into EvaP providing all the login options available. The OpenID login is thought to be used for\n       internal users. The login key mechanism is meant to be used to include external participants, e.g. visiting\n       students or visiting contributors. A login with email and password is available if OpenID is deactivated.\n    \"\"\"\n\n    # parse the form data into the respective form\n    submit_type = request.POST.get(\"submit_type\", \"no_submit\")\n    new_key_form = NewKeyForm(request.POST if submit_type == \"new_key\" else None)\n    login_email_form = LoginEmailForm(request, request.POST if submit_type == \"login_email\" else None)\n\n    # process form data\n    if request.method == 'POST':\n        if new_key_form.is_valid():\n            # user wants a new login key\n            profile = new_key_form.get_user()\n            profile.ensure_valid_login_key()\n            profile.save()\n\n            EmailTemplate.send_login_url_to_user(new_key_form.get_user())\n\n            messages.success(request, _(\"We sent you an email with a one-time login URL. Please check your inbox.\"))\n            return redirect('evaluation:index')\n\n        if login_email_form.is_valid():\n            # user would like to login with email and password and passed password test\n            auth.login(request, login_email_form.get_user())\n\n            # clean up our test cookie\n            if request.session.test_cookie_worked():\n                request.session.delete_test_cookie()\n            return redirect('evaluation:index')\n\n    # if not logged in by now, render form\n    if not request.user.is_authenticated:\n        # set test cookie to verify whether they work in the next step\n        request.session.set_test_cookie()\n\n        template_data = dict(\n            new_key_form=new_key_form,\n            login_email_form=login_email_form,\n            openid_active=settings.ACTIVATE_OPEN_ID_LOGIN,\n        )\n        return render(request, \"index.html\", template_data)\n\n    # check for redirect variable\n    redirect_to = request.GET.get(\"next\", None)\n    if redirect_to is not None:\n        return redirect(redirect_to)\n\n    return redirect_user_to_start_page(request.user)\n\n\n@no_login_required\ndef login_key_authentication(request, key):\n    user = auth.authenticate(request, key=key)\n\n    if user and not user.is_active:\n        messages.error(request, _(\"Inactive users are not allowed to login.\"))\n        return redirect('evaluation:index')\n\n    # If we already have an authenticated user don't try to login a new user. Show an error message if another user\n    # tries to login with a URL in this situation.\n    if request.user.is_authenticated:\n        if user != request.user:\n            messages.error(request, _(\"Another user is currently logged in. Please logout first and then use the login URL again.\"))\n        return redirect('evaluation:index')\n\n    if user and user.login_key_valid_until >= date.today():\n        if request.method != \"POST\":\n            template_data = {\n                'username': user.full_name\n            }\n            return render(request, \"external_user_confirm_login.html\", template_data)\n\n        # User is valid. Set request.user and persist user in the session by logging the user in.\n        request.user = user\n        auth.login(request, user)\n        messages.success(request, _(\"Logged in as %s.\") % user.full_name)\n        # Invalidate the login key, but keep it stored so we can later identify the user that is trying to login and send a new link\n        user.login_key_valid_until = date.today() - timedelta(1)\n        user.save()\n    elif user:\n        # A user exists, but the login key is not valid anymore. Send the user a new one.\n        user.ensure_valid_login_key()\n        EmailTemplate.send_login_url_to_user(user)\n        messages.warning(request, _(\"The login URL is not valid anymore. We sent you a new one to your email address.\"))\n    else:\n        messages.warning(request, _(\"Invalid login URL. Please request a new one below.\"))\n\n    return redirect('evaluation:index')\n\n\n@no_login_required\ndef faq(request):\n    return render(request, \"faq.html\", dict(sections=FaqSection.objects.all()))\n\n\n@no_login_required\ndef legal_notice(request):\n    return render(request, \"legal_notice.html\", dict())\n\n\n@require_POST\n@login_required\ndef contact(request):\n    message = request.POST.get(\"message\")\n    title = request.POST.get(\"title\")\n    email = request.user.email or f\"User {request.user.id}\"\n    subject = f\"[EvaP] Message from {email}\"\n\n    if message:\n        mail = EmailMessage(\n            subject=subject,\n            body=\"{}\\n{}\\n\\n{}\".format(title, request.user.email, message),\n            to=[settings.CONTACT_EMAIL])\n        try:\n            mail.send()\n            logger.info('Sent contact email: \\n{}\\n'.format(mail.message()))\n            return HttpResponse()\n        except Exception:\n            logger.exception('An exception occurred when sending the following contact email:\\n{}\\n'.format(mail.message()))\n            raise\n\n    return HttpResponseBadRequest()\n\n\n@no_login_required\n@require_POST\ndef set_lang(request):\n    if request.user.is_authenticated:\n        user = request.user\n        user.language = request.POST['language']\n        user.save()\n\n    return set_language(request)\n", "path": "evap/evaluation/views.py"}]}