nim-in-action-code
nim-in-action-code copied to clipboard
Returned values in Listing 7.30 should be reversed?
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
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.