prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Only internal redirects
  The platform should only redirect to internal pages after logging in.
  
  (handled in `evaluation/views.py index`)
  
  
  </issue>
  <code>
  [start of evap/evaluation/views.py]
  1 from django.contrib import messages
  2 from django.contrib.auth import login as auth_login
  3 from django.shortcuts import redirect, render
  4 from django.utils.translation import ugettext as _
  5 
  6 from evap.evaluation.forms import NewKeyForm, LoginKeyForm, LoginUsernameForm
  7 from evap.evaluation.models import UserProfile, FaqSection, EmailTemplate, Semester
  8 
  9 
  10 def index(request):
  11     """Main entry page into EvaP providing all the login options available. THe username/password
  12        login is thought to be used for internal users, e.g. by connecting to a LDAP directory.
  13        The login key mechanism is meant to be used to include external participants, e.g. visiting
  14        students or visiting contributors.
  15     """
  16 
  17     # parse the form data into the respective form
  18     submit_type = request.POST.get("submit_type", "no_submit")
  19     new_key_form = NewKeyForm(request.POST if submit_type == "new_key" else None)
  20     login_key_form = LoginKeyForm(request.POST if submit_type == "login_key" else None)
  21     login_username_form = LoginUsernameForm(request, request.POST if submit_type == "login_username" else None)
  22 
  23     # process form data
  24     if request.method == 'POST':
  25         if new_key_form.is_valid():
  26             # user wants a new login key
  27             profile = new_key_form.get_user()
  28             profile.generate_login_key()
  29             profile.save()
  30 
  31             EmailTemplate.send_login_key_to_user(new_key_form.get_user())
  32 
  33             messages.success(request, _("Successfully sent email with new login key."))
  34         elif login_key_form.is_valid():
  35             # user would like to login with a login key and passed key test
  36             auth_login(request, login_key_form.get_user())
  37         elif login_username_form.is_valid():
  38             # user would like to login with username and password and passed password test
  39             auth_login(request, login_username_form.get_user())
  40 
  41             # clean up our test cookie
  42             if request.session.test_cookie_worked():
  43                 request.session.delete_test_cookie()
  44 
  45     # if not logged in by now, render form
  46     if not request.user.is_authenticated():
  47         # set test cookie to verify whether they work in the next step
  48         request.session.set_test_cookie()
  49 
  50         template_data = dict(new_key_form=new_key_form, login_key_form=login_key_form, login_username_form=login_username_form)
  51         return render(request, "index.html", template_data)
  52     else:
  53         user, created = UserProfile.objects.get_or_create(username=request.user.username)
  54 
  55         # check for redirect variable
  56         redirect_to = request.GET.get("next", None)
  57         if redirect_to is not None:
  58             if redirect_to.startswith("/staff/"):
  59                 if request.user.is_staff:
  60                     return redirect(redirect_to)
  61             elif redirect_to.startswith("/grades/"):
  62                 if request.user.is_grade_publisher:
  63                     return redirect(redirect_to)
  64             elif redirect_to.startswith("/contributor/"):
  65                 if user.is_contributor:
  66                     return redirect(redirect_to)
  67             elif redirect_to.startswith("/student/"):
  68                 if user.is_participant:
  69                     return redirect(redirect_to)
  70             else:
  71                 return redirect(redirect_to)
  72 
  73         # redirect user to appropriate start page
  74         if request.user.is_staff:
  75             return redirect('staff:index')
  76         elif request.user.is_grade_publisher:
  77             return redirect('grades:semester_view', Semester.active_semester().id)
  78         elif user.is_contributor_or_delegate:
  79             return redirect('contributor:index')
  80         elif user.is_participant:
  81             return redirect('student:index')
  82         else:
  83             return redirect('results:index')
  84 
  85 
  86 def faq(request):
  87     return render(request, "faq.html", dict(sections=FaqSection.objects.all()))
  88 
  89 def legal_notice(request):
  90     return render(request, "legal_notice.html", dict())
  91
  [end of evap/evaluation/views.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/evap/evaluation/views.py b/evap/evaluation/views.py
  --- a/evap/evaluation/views.py
  +++ b/evap/evaluation/views.py
  @@ -2,13 +2,14 @@
   from django.contrib.auth import login as auth_login
   from django.shortcuts import redirect, render
   from django.utils.translation import ugettext as _
  +from django.core.urlresolvers import resolve, Resolver404
   
   from evap.evaluation.forms import NewKeyForm, LoginKeyForm, LoginUsernameForm
   from evap.evaluation.models import UserProfile, FaqSection, EmailTemplate, Semester
   
   
   def index(request):
  -    """Main entry page into EvaP providing all the login options available. THe username/password
  +    """Main entry page into EvaP providing all the login options available. The username/password
          login is thought to be used for internal users, e.g. by connecting to a LDAP directory.
          The login key mechanism is meant to be used to include external participants, e.g. visiting
          students or visiting contributors.
  @@ -68,7 +69,12 @@
                   if user.is_participant:
                       return redirect(redirect_to)
               else:
  -                return redirect(redirect_to)
  +                try:
  +                    resolve(redirect_to)
  +                except Resolver404:
  +                    pass
  +                else:
  +                    return redirect(redirect_to)
   
           # redirect user to appropriate start page
           if request.user.is_staff:
  
verification_info: {"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@@ -2,13 +2,14 @@\n from django.contrib.auth import login as auth_login\n from django.shortcuts import redirect, render\n from django.utils.translation import ugettext as _\n+from django.core.urlresolvers import resolve, Resolver404\n \n from evap.evaluation.forms import NewKeyForm, LoginKeyForm, LoginUsernameForm\n from evap.evaluation.models import UserProfile, FaqSection, EmailTemplate, Semester\n \n \n def index(request):\n-    \"\"\"Main entry page into EvaP providing all the login options available. THe username/password\n+    \"\"\"Main entry page into EvaP providing all the login options available. The username/password\n        login is thought to be used for internal users, e.g. by connecting to a LDAP directory.\n        The login key mechanism is meant to be used to include external participants, e.g. visiting\n        students or visiting contributors.\n@@ -68,7 +69,12 @@\n                 if user.is_participant:\n                     return redirect(redirect_to)\n             else:\n-                return redirect(redirect_to)\n+                try:\n+                    resolve(redirect_to)\n+                except Resolver404:\n+                    pass\n+                else:\n+                    return redirect(redirect_to)\n \n         # redirect user to appropriate start page\n         if request.user.is_staff:\n", "issue": "Only internal redirects\nThe platform should only redirect to internal pages after logging in.\n\n(handled in `evaluation/views.py index`)\n\n", "before_files": [{"content": "from django.contrib import messages\nfrom django.contrib.auth import login as auth_login\nfrom django.shortcuts import redirect, render\nfrom django.utils.translation import ugettext as _\n\nfrom evap.evaluation.forms import NewKeyForm, LoginKeyForm, LoginUsernameForm\nfrom evap.evaluation.models import UserProfile, FaqSection, EmailTemplate, Semester\n\n\ndef index(request):\n    \"\"\"Main entry page into EvaP providing all the login options available. THe username/password\n       login is thought to be used for internal users, e.g. by connecting to a LDAP directory.\n       The login key mechanism is meant to be used to include external participants, e.g. visiting\n       students or visiting contributors.\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_key_form = LoginKeyForm(request.POST if submit_type == \"login_key\" else None)\n    login_username_form = LoginUsernameForm(request, request.POST if submit_type == \"login_username\" 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.generate_login_key()\n            profile.save()\n\n            EmailTemplate.send_login_key_to_user(new_key_form.get_user())\n\n            messages.success(request, _(\"Successfully sent email with new login key.\"))\n        elif login_key_form.is_valid():\n            # user would like to login with a login key and passed key test\n            auth_login(request, login_key_form.get_user())\n        elif login_username_form.is_valid():\n            # user would like to login with username and password and passed password test\n            auth_login(request, login_username_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(new_key_form=new_key_form, login_key_form=login_key_form, login_username_form=login_username_form)\n        return render(request, \"index.html\", template_data)\n    else:\n        user, created = UserProfile.objects.get_or_create(username=request.user.username)\n\n        # check for redirect variable\n        redirect_to = request.GET.get(\"next\", None)\n        if redirect_to is not None:\n            if redirect_to.startswith(\"/staff/\"):\n                if request.user.is_staff:\n                    return redirect(redirect_to)\n            elif redirect_to.startswith(\"/grades/\"):\n                if request.user.is_grade_publisher:\n                    return redirect(redirect_to)\n            elif redirect_to.startswith(\"/contributor/\"):\n                if user.is_contributor:\n                    return redirect(redirect_to)\n            elif redirect_to.startswith(\"/student/\"):\n                if user.is_participant:\n                    return redirect(redirect_to)\n            else:\n                return redirect(redirect_to)\n\n        # redirect user to appropriate start page\n        if request.user.is_staff:\n            return redirect('staff:index')\n        elif request.user.is_grade_publisher:\n            return redirect('grades:semester_view', Semester.active_semester().id)\n        elif user.is_contributor_or_delegate:\n            return redirect('contributor:index')\n        elif user.is_participant:\n            return redirect('student:index')\n        else:\n            return redirect('results:index')\n\n\ndef faq(request):\n    return render(request, \"faq.html\", dict(sections=FaqSection.objects.all()))\n\ndef legal_notice(request):\n    return render(request, \"legal_notice.html\", dict())\n", "path": "evap/evaluation/views.py"}]}