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

User authentication with sessions


We implemented the functionalities that register new users in our system. The next step is to authenticate these users. Let's first provide an interface to enter a username and password. We need to add a new route handler in frontend/js/app.js:

Router
.add('login', function() {
    var p = new Login();
    showPage(p);
})

All the other pages so far use the same idea. We will initialize a new controller and pass it to the showPage helper. The template that is used here is as follows:

// frontend/tpl/login.html
<header>
  <navigation></navigation>
</header>
<div class="hero">
  <h1>Login</h1>
</div>
<form>
  {{#if error && error != ''}}
    <div class="error">{{error}}</div>
  {{/if}}
  {{#if success && success != ''}}
    <div class="success">{{{success}}}</div>
  {{else}}
    <label for="email">Email</label>
    <input type="text" id="email" value="...