English subtitles

← Logout Solution - Web Development

Get Embed Code
4 Languages

Showing Revision 8 created 05/25/2016 by Udacity Robot.

  1. Here we are on that Welcome page.
  2. If I reload this page, we keep seeing the same thing.
  3. The last thing I asked you to do was implement "Log out"
  4. So this URL, when you go to it, redirects you to the "Sign up" page.
  5. If I were to go back to the "Welcome page" and reload this,
  6. it redirects us to the "Sign up" page because our cookie has been deleted.
  7. The way you log somebody out is you delete that cookie.
  8. I didn't say that in the lecture. Hopefully you managed to figure that out.
  9. Let's go ahead and see that in action again.
  10. Let's log in. You can see we have a cookie. The user ID cookie equals 5.
  11. That's the user ID for spez in this machine.
  12. If I go to logout, and we go look at our cookie again,
  13. we can see that the user ID is the user ID cookie.
  14. It's just blank. There is the user ID cookie. There's nothing in it.
  15. That's how "Logout" works. Let's look at the code for this.
  16. The first thing we have is our "Logout" handler.
  17. So I map slash logout to the logout handler.
  18. When we look at the "logout handler" you can see it calls "self dot logout"
  19. which is the Find up on Blog Handler and it redirects the Signup.
  20. Let's look at this Logout function. Here it is. Remember we are in Class Blog Handler
  21. where I've put all this helpful generic stuff that other Handlers may use.
  22. All Logoff does is it sets the cookie User ID to nothing.
  23. Instead of setting Cookie = Value, we just set Cookie = Nothing
  24. and we keep the same path so we're setting and overwriting the same cookie.
  25. If we didn't have these path variables here, or this path parameter here on the cookie,
  26. we would actually overwrite the--well, we might set the cookie on
  27. slash login or slash signup to default where you're on,
  28. and then when you go to the Welcome page you wouldn't be logged in.
  29. That would cause problems so we make sure we set the cookie on path slash
  30. and we delete the cookie off of path slash.
  31. And that's how Logout works.
  32. If you got all that you did a very good job.
  33. One of the more complicated things you do when you're writing
  34. web apps is all this kind of cookie and hashing and all that manipulation,
  35. but you can also start doing some really clever things.
  36. While a lot of frameworks do a lot of this for you, I think it's really important
  37. to understand how it works because you'll often find yourself in a situation
  38. where you need to hide some data in a cookie or maybe have a
  39. special type of hash that represents some piece of information and that sort of thing.
  40. We do that on Reddit all the time for anti-cheating stuff.
  41. Knowing how this all fits together I think is really important.
  42. That's why I made you do all this.