We'll start as we did in the last chapter; by adding user account to our basic application. We won't go over the whole process again; you can copy it from the previous chapter's application. There's only one change we have to make. In the app.post('/create')
route, we create a userAttrs
object that we store in the database. Users of this application will have three application-specific values to store:
score
: This is their highest scoretime
: This is their lowest timegames
: This is an array of the games they have played
Here's the code to create the userAttrs
object:
var userAttrs = { username: req.body.username, passwordHash: signin.hashPassword(req.body.password), score: 0, time: 3600, games: [] };
With this in place, and all the other user account creation code we've previously created, we have the shell of an application, ready to customize.