Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned values in Listing 7.30 should be reversed? #8

Open
hokamoto opened this issue Aug 31, 2019 · 1 comment
Open

Returned values in Listing 7.30 should be reversed? #8

hokamoto opened this issue Aug 31, 2019 · 1 comment

Comments

@hokamoto
Copy link

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
@mikebelanger
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants