Tut08 NodeJS-3
Tut08 NodeJS-3
Tutorial 8
To begin this tutorial, please create a Node project or use an existing one. When you
finish, zip all your source codes (excluding the node_modules folder) to submit to this
tutorial’s submission box. The zip file’s name should follow this format:
tclass_sid.zip where tclass is your tutorial class name (e.g. tut01, tut02, etc.)
and sid is your student’s ID (e.g. 2101040015).
Requirements:
o Encryption Function:
o Decryption Function:
2. Key length:
o The key length for AES-128-ECB is 16 bytes. Ensure that the provided key
is exactly 16 bytes long (128 bits).
4. Put these functions in a CommonJS module and re-use them in the next
activities.
Requirements:
id (User ID)
username (Username)
password (Password)
2. Create Endpoints:
o GET Endpoint /login: Create an endpoint to display the login form. This
form should allow users to enter their username and password.
o login.ejs: Create an EJS template to display the login form and any
error messages.
Template Syntax: Replace EJS syntax (<%= %>, <% %>, etc.) with Handlebars
syntax ({{ }}, {{#if }}, etc.).
Error Handling and Data Display: Update the login form and error display logic
to use Handlebars expressions and helpers.
Requirements:
o Model: Create a model to handle user data interactions. This model will
include functions to read from and validate against the users.json file.
o View: Separate the Handlebars templates into a views directory. Ensure
your views (login.hbs and profile.hbs) only contain presentation logic.
2. Update Routes:
o Refactor the existing route handlers to use the new controllers. Ensure
routes handle requests by calling appropriate methods in the controllers.
3. MVC Structure:
File: models/userModel.js
o Controller: Contains the logic to manage user requests and interact with
models and views.
File: controllers/userController.js
File: middleware/cookieMiddleware.js