Book Image

Node.js By Example

Book Image

Node.js By Example

Overview of this book

Table of Contents (18 chapters)
Node.js By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Managing a user's profile


The previous sections of this chapter gave us enough knowledge to update the information saved in the database. Again, we need to create a page in the frontend that has an HTML form. The difference here is that the input fields of the form should be filled by default with the data of the current user. So, let's start by adding a route handler for the /profile URL:

Route
.add('profile', function() {
  if(userModel.isLogged()) {
    var p = new Profile();
    showPage(p);
  } else {
    Router.navigate('login');
  }      
})

There is no reason to allow access to this page if the user is not logged in. A simple authentication check before calling the showPage helper forwards the user to the login page if needed.

The template that we need for the Profile controller is identical to the one that we used for registration. There are only two things that we have to change—we need to remove the email field and update the label of the button from Register to Update. The removing...