Skip to content
Snippets Groups Projects
Bishal Rai's avatar
Bishal Rai authored
cdc9ce6b

#APP REQUIREMENT LIST:

1.hyperlink reference in all pages and links to all pages on the home page including the logout page -I have added hyperlink reference in all pages to get back to home page and navigation bar in home page to navigate to different pages in (index.html) file.

2.About page -I have listed what users can do with the application in list format and link to homepage in (about.html) file.

3.Register form includes first name, last name, email as well as username and password -I have added input fields which includes firstname, lastname, email, password and username in (register.html) file.It stores hashed password and displays message when user data is saved to database. It checks the email format and password length. I have used 'trim()' to remove extra space in the beginning and at the end of the text input such as firstname in (main.js) file.

4.Login form -Login form has two input:username and password. It validates username and password. If username or password is wrong, it displays error message to the user. So user can only signin if both the username and password are correct.(login.html)

5.Logout page -There is a way to logout, a message is displayed upon successful logout.

6.Add food page -User can add new food item using add food page form. It displays message when food data are saved to the database.(new.ejs)

7.Search food page -User can search food by typing name in the input field. It performs advanced search. For example: when you type letter "a", it shows all the food names containing the letter "a" and so on. When the foodname does not match it displays error message and successful when the foodname is correct.(foodsearch.ejs)

8.Update and delete page -User can update food from foodlist page where they can click on edit button and update food data. Delete button helps to delete the food along with its data.Application displays confirmation box when user clicks on the delete button. It deletes the food using its unique id when user confirms the process.(index.ejs)

9.Listfood page -It displays all the food saved in the database along with its nutritional informations in a tabular format.When user clicks on the "info" button, it displays that particuar food data in the screen.(index.ejs)

10.Food API -There is a basic API displayed on '/food' route listing all foods stored in the database in JSON format. The link is present in the home page navbar.

11.Form validation -I have implemented form validation in the application. Email input must be in standart format and password must be at least 8 characters long. I have also used sanitisation and to sanitise data. In addfood form, I have set number input for calories, typicalvalue, sugar, salt, carbs, fat and protein. So user cannot enter text on those fields. I have also implemented only text type input on weatherform. So user can only enter text string for city name.

  1. I have added comments to make it readable.

13.access control for the addfood, updatefood and foodlist pages -I have implemented the access control for the list page so that only loggedin users can access it. If the user is not loggedin, it redirects to the login page.

-I have implemented sanitisation such as 'req.sanitize(req.body.password)','req.sanitize(req.body.fname)' to sanitise the inputs before storing and 'isEmail().normalizeEmail()' to make sure email standard format is met. I learnt that using sanitisaion we can store data in the right format and free of noise. Using 'trim()', we can remove unnecessary spaces in the beginning and the end of the text. Similarly using 'isEmail().normalizeEmail()', we can store email address in small letters and standard format which helps in data manipulation. I got to explore many things while developing this application such as packages, validation and sanitisation, schema design and relationship, API, etc.

DATABASE AND COLLECTION

Entities of my database are: Food, Customer and Recipe

Database attributes are as follows: Food- name, id, calories, carbs, typical value, unit value, protein, fat, salt, sugar Recipe- name, id, description Customer-name, email, username

Data types are as follows: Food- name: String , id:String Recipe- name:String, id:String, description:String Customer- firstname:String, email:String, username:String , lastname:String, password:String

FoodSchema: const articleSchema = new mongoose.Schema({ name: { type: String, required: true }, typicalvalues: { type: String ,required: true }, unitvalue: { type: String, required: true }, calories: { type: String, required: true }, carbs: { type: String, required: true }, fat: { type: String, required: true }, protein: { type: String, required: true }, salt: { type: String, required: true }, sugar: { type: String, required: true }, createdAt: { type: Date, default: Date.now }, slug: { type: String, required: true, unique: true }, sanitizedHtml:{ type: String, required: true } })

Food data in JSON format: [{"_id":"606f9fcd0ea1fd0f619e8c4e","createdAt":"2021-04-09T00:29:01.486Z", "name":"PITTA bread","typicalvalues":"100", "unitvalue":"gram","calories":"55","carbs":"33", "fat":"4","protein":"3","salt":"1","sugar":"1", "slug":"pitta-bread","sanitizedHtml":"

gram

\n","__v":0}