Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Create the user profile page using the Pug templating language.Add programming logic to password protect the profile page for unauthorized users, or show user information for the currently logged in user.
Profile template code
profile.pug
extends layout
block content
.main.container.clearfix
.row
.col-md-8.col-md-offset-2
h1.display-4
img.avatar.img-circle.hidden-xs-down(src='/images/avatar.png', alt='avatar')
| #{name}
h2.favorite-book Favorite Book
| #{favorite}
GET /profile route
// GET /profile
router.get('/profile', function(req, res, next) {
if (! req.session.userId ) {
var err = new Error("You are not authorized to view this page.");
err.status = 403;
return next(err);
}
User.findById(req.session.userId)
.exec(function (error, user) {
if (error) {
return next(error);
} else {
return res.render('profile', { title: 'Profile', name: user.name, favorite: user.favoriteBook });
}
});
});
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up