Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: User input and HTML forms
Lecture: Logging out
0:00 Let's just round out this demo part of this chapter
0:04 by closing out what we're doing with the users.
0:06 We've done all of these things
0:07 and that let us explore working with forms.
0:09 Let's go ahead and add logout.
0:10 Technically this has nothing to do with forms
0:13 but we have been doing this user stuff
0:15 so let's just finish that up real quick.
0:17 So I already have this /account/logout route
0:22 and we're going to come over to here and we're just going to add
0:28 another little action method here. We'll say logout.
0:33 You'll see we don't need a renderer
0:35 and we don't need to set the get.
0:41 And we're going to return.
0:42 When somebody logs out
0:43 we got to figure out where do they go.
0:44 Let's return them to http found at just /, okay?
0:49 How do we log them out?
0:51 Well remember the way they're logged in
0:52 is they have a cookie that they're passing back and forth.
0:55 All we're going to do is delete that cookie
0:57 their session is gone.
0:59 So we have cookie_auth and it has a logout function.
1:03 And we give it the request, that's it.
1:07 Let's look really quick at that.
1:08 It just said to call back to say delete this
1:10 which goes to the response, deletes the cookie.
1:14 All right, well that should be pretty easy.
1:15 Let's try logging out.
1:20 Can see right now we're logged in.
1:22 We can go to our account page to click this.
1:24 Boom, login register.
1:26 I try to go back to account, can't go there.
1:30 We're logged out.
1:31 We got to go log in first.
1:33 Perfect, huh? All right, well that rounds out the user stuff.