Skip to content

Commit

Permalink
Logout using POST
Browse files Browse the repository at this point in the history
  • Loading branch information
he3lixxx committed Apr 24, 2023
1 parent dface33 commit 3c0338b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion evap/evaluation/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@
<a class="nav-link dropdown-toggle" href="#" id="navbarUserDropdownMenuLink" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="fas fa-user"></span> {{ user.full_name }}</a>
<div class="dropdown-menu dropdown-menu-end dropdown-menu-tight" aria-labelledby="navbarUserDropdownMenuLink">
<a class="dropdown-item" href="{% url 'evaluation:profile_edit' %}">{% trans 'Profile' %}</a>
<a class="dropdown-item" href="{% url 'django-auth-logout' %}">{% trans 'Logout' %}</a>
<form method="post" action="{% url 'django-auth-logout' %}" id="logout-form">
{% csrf_token %}
<button type="submit" class="dropdown-item">{% trans 'Logout' %}</button>
</form>
</div>
</li>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions evap/evaluation/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_login_key_valid_only_once(self):
page = self.app.post(url_with_key).follow().follow()
self.assertContains(page, "Logout")

page = self.app.get(reverse("django-auth-logout")).follow()
page = page.forms["logout-form"].submit().follow()
self.assertNotContains(page, "Logout")

page = self.app.get(url_with_key).follow()
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_entering_staff_mode_after_logout_and_login(self):
self.assertContains(page, "Logout")

# log out user
page = self.app.get(reverse("django-auth-logout")).follow()
page = page.forms["logout-form"].submit().follow()
self.assertNotContains(page, "Logout")

# log user in again
Expand Down
2 changes: 1 addition & 1 deletion evap/grades/templates/grades_upload_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h3 class="mb-3">
{% blocktrans with course=course.name semester=semester.name %}Upload midterm grades for {{ course }} ({{ semester }}){% endblocktrans %}
{% endif %}
</h3>
<form method="POST" class="form-horizontal" enctype="multipart/form-data">
<form method="POST" class="form-horizontal" id="grades-upload-form" enctype="multipart/form-data">
{% csrf_token %}
<div class="card mb-3">
<div class="card-body">
Expand Down
2 changes: 1 addition & 1 deletion evap/grades/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_edit_grades(self) -> None:
previous_modifying_user = self.grade_document.last_modified_user
self.assertNotEqual(previous_modifying_user, self.grade_publisher)
response = self.app.get(self.url, user=self.grade_publisher)
form = response.forms[3]
form = response.forms["grades-upload-form"]
form["description_en"] = "Absolutely final grades"
form["file"] = ("grades.txt", b"You did great!")
form.submit()
Expand Down
4 changes: 3 additions & 1 deletion evap/student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ def test_user_logged_out(self):
page = self.app.get(self.url, user=self.voting_user1, status=200)
form = page.forms["student-vote-form"]
self.fill_form(form)
page = self.app.get(reverse("django-auth-logout"), user=self.voting_user1, status=302)

page = page.forms["logout-form"].submit(status=302)

response = form.submit(status=302)
self.assertNotIn(SUCCESS_MAGIC_STRING, response)

Expand Down

0 comments on commit 3c0338b

Please sign in to comment.