Skip to content

Commit ead9eaf

Browse files
committed
feed csrf token from 18
1 parent c834ceb commit ead9eaf

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

chapter_18_spiking_custom_auth.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ form for the login email:
842842
class="form-control"
843843
placeholder="[email protected]"
844844
/>
845+
{% csrf_token %}
845846
</div>
846847
</form>
847848
</div>

chapter_19_mocking.asciidoc

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,7 @@ see if they start to make more sense as we use them more.
504504

505505

506506

507-
Getting the FT a Little Further Along
508-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
507+
==== Getting the FT a Little Further Along
509508

510509
First let's get back to our FT and see where it's failing:
511510

@@ -517,27 +516,23 @@ AssertionError: 'Check your email' not found in 'Superlists\nEnter email to log
517516
in:\nStart a new To-Do list'
518517
----
519518

520-
Submitting the email address currently has no effect, because the form isn't
521-
sending the data anywhere. Let's wire it up in
522-
'base.html':footnote:[I've split
523-
the form tag across three lines so it fits nicely in the book. If
524-
you've not seen it before, it may look a little weird to you, but it is valid
525-
HTML. You don't have to use it if you don't like it though. :)]
526-
519+
Submitting the email address currently has no effect,
520+
because the form isn't sending the data anywhere.
521+
Let's wire it up in _base.html_:
527522

528523
[role="sourcecode small-code"]
529524
.src/lists/templates/base.html (ch19l012)
530525
====
531526
[source,html]
532527
----
533-
<form class="navbar-form navbar-right"
534-
method="POST"
535-
action="{% url 'send_login_email' %}">
528+
<form method="POST" action="{% url 'send_login_email' %}">
536529
----
537530
====
538531

539-
Does that help? Nope, same error. Why? Because we're not actually displaying
540-
a success message after we send the user an email. Let's add a test for that.
532+
Does that help? Nope, same error. Why?
533+
Because we're not actually displaying a success message
534+
after we send the user an email.
535+
Let's add a test for that.
541536

542537

543538
==== Testing the Django Messages Framework
@@ -1850,16 +1845,24 @@ and non–logged-in users (which our FT relies on):
18501845
<div class="container-fluid">
18511846
<a class="navbar-brand" href="/">Superlists</a>
18521847
{% if user.email %}
1853-
<!-- TODO put in a ul -->
1854-
<span class="navbar-text">Logged in as {{ user.email }}</span>
1855-
<a href="#">Log out</a>
1848+
<ul>
1849+
<span class="navbar-text">Logged in as {{ user.email }}</span>
1850+
<a href="{% url 'logout' %}">Log out</a>
1851+
</ul>
18561852
{% else %}
1857-
<form class="navbar-form navbar-right"
1858-
method="POST"
1859-
action="{% url 'send_login_email' %}">
1860-
<span>Enter email to log in:</span>
1861-
<input class="form-control" name="email" type="text" />
1862-
{% csrf_token %}
1853+
<form method="POST" action="{% url 'send_login_email' %}">
1854+
<div class="input-group">
1855+
<label class="navbar-text me-2" for="id_email_input">
1856+
Enter your email to log in
1857+
</label>
1858+
<input
1859+
id="id_email_input"
1860+
name="email"
1861+
class="form-control"
1862+
placeholder="[email protected]"
1863+
/>
1864+
{% csrf_token %}
1865+
</div>
18631866
</form>
18641867
{% endif %}
18651868
</div>

0 commit comments

Comments
 (0)