nim-in-action-code icon indicating copy to clipboard operation
nim-in-action-code copied to clipboard

Returned values in Listing 7.30 should be reversed?

Open hokamoto opened this issue 6 years ago • 1 comments

I think returned values in Listing 7.30 should be reversed.

proc userLogin(db: Database, request: Request, user: var User): bool =
  if request.cookies.hasKey("username"):
    if not db.findUser(request.cookies["username"], user):
      user = User(username: request.cookies["username"], following: @[])
      db.create(user)
      return false
    else:
      return true

hokamoto avatar Aug 31 '19 11:08 hokamoto

I really enjoyed this Chapter, but yeah that part threw me off too. If userLogin only returns true when there's a new user - then there's no way of seeing updates from others.

Somewhat related: after reversing the truth values as per @hokamoto, this had to be added to the renderUser function in ../Tweeter/src/views/user.nim:

<div id="user">
  <h1>${user.username}</h1>
  <span>Following: ${$user.following.len}</span>
#  if user.username notin currentUser.following and user.username != currentUser.username:
    <form action="follow" method="post">
      <input type="hidden" name="follower" value="${currentUser.username}">
      <input type="hidden" name="target" value="${user.username}">
      <input type="submit" value="Follow">
    </form>
#  end if
#

In order to enable the "Follow" button for anyone other than the logged in user's page.

I know this app is just a 'demonstration' app meant to show basic web dev functionality, but those minor changes above made testing this app feel easier.

mikebelanger avatar Apr 07 '20 16:04 mikebelanger