├── .env
├── .github
└── stale.yml
├── .gitignore
├── app.js
├── config
└── index.js
├── db
└── index.js
├── error-handling
└── index.js
├── models
└── User.model.js
├── package.json
├── public
├── images
│ └── favicon.ico
├── js
│ └── script.js
└── stylesheets
│ └── style.css
├── readme.md
├── routes
└── index.js
├── server.js
└── views
├── error.hbs
├── index.hbs
├── layout.hbs
└── not-found.hbs
/.env:
--------------------------------------------------------------------------------
1 | PORT=3000
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Configuration for probot-stale - https://github.com/probot/stale
2 |
3 | # Number of days of inactivity before an Issue or Pull Request becomes stale
4 | daysUntilStale: 21
5 |
6 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
7 | exemptLabels:
8 | - bugs
9 | - enhancements
10 |
11 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
12 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
13 | daysUntilClose: 7
14 |
15 | # Label to use when marking as stale
16 | staleLabel: stale
17 |
18 | # Comment to post when marking as stale. Set to `false` to disable
19 | markComment: >
20 | This pull request has been automatically marked as stale because it didn't have any recent activity. It will be closed if no further activity occurs. Thank you
21 | for your contributions.
22 | closeComment: >
23 | This pull request is closed. Thank you.
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependency directory
2 | node_modules
3 |
4 | # Debug log from npm
5 | npm-debug.log
6 |
7 | # Environment Variables should NEVER be published
8 | # We are submitting it for learning purposes
9 | # .env
10 |
11 | # for maintenance purposes - not best practices
12 | package-lock.json
13 |
14 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | // ℹ️ Gets access to environment variables/settings
2 | // https://www.npmjs.com/package/dotenv
3 | require('dotenv/config');
4 |
5 | // ℹ️ Connects to the database
6 | require('./db');
7 |
8 | // Handles http requests (express is node js framework)
9 | // https://www.npmjs.com/package/express
10 | const express = require('express');
11 |
12 | // Handles the handlebars
13 | // https://www.npmjs.com/package/hbs
14 | const hbs = require('hbs');
15 |
16 | const app = express();
17 |
18 | // ℹ️ This function is getting exported from the config folder. It runs most middlewares
19 | require('./config')(app);
20 |
21 | // default value for title local
22 | const projectName = 'lab-express-basic-auth';
23 | const capitalized = string => string[0].toUpperCase() + string.slice(1).toLowerCase();
24 |
25 | app.locals.title = `${capitalized(projectName)}- Generated with Ironlauncher`;
26 |
27 | // 👇 Start handling routes here
28 | const index = require('./routes/index');
29 | app.use('/', index);
30 |
31 | // ❗ To handle errors. Routes that don't exist or errors that you handle in specific routes
32 | require('./error-handling')(app);
33 |
34 | module.exports = app;
35 |
36 |
--------------------------------------------------------------------------------
/config/index.js:
--------------------------------------------------------------------------------
1 | // We reuse this import in order to have access to the `body` property in requests
2 | const express = require("express");
3 |
4 | // ℹ️ Responsible for the messages you see in the terminal as requests are coming in
5 | // https://www.npmjs.com/package/morgan
6 | const logger = require("morgan");
7 |
8 | // ℹ️ Needed when we deal with cookies (we will when dealing with authentication)
9 | // https://www.npmjs.com/package/cookie-parser
10 | const cookieParser = require("cookie-parser");
11 |
12 | // ℹ️ Serves a custom favicon on each request
13 | // https://www.npmjs.com/package/serve-favicon
14 | const favicon = require("serve-favicon");
15 |
16 | // ℹ️ global package used to `normalize` paths amongst different operating systems
17 | // https://www.npmjs.com/package/path
18 | const path = require("path");
19 |
20 | // Middleware configuration
21 | module.exports = (app) => {
22 | // In development environment the app logs
23 | app.use(logger("dev"));
24 |
25 | // To have access to `body` property in the request
26 | app.use(express.json());
27 | app.use(express.urlencoded({ extended: false }));
28 | app.use(cookieParser());
29 |
30 | // Normalizes the path to the views folder
31 | app.set("views", path.join(__dirname, "..", "views"));
32 | // Sets the view engine to handlebars
33 | app.set("view engine", "hbs");
34 | // Handles access to the public folder
35 | app.use(express.static(path.join(__dirname, "..", "public")));
36 |
37 | // Handles access to the favicon
38 | app.use(favicon(path.join(__dirname, "..", "public", "images", "favicon.ico")));
39 | };
40 |
--------------------------------------------------------------------------------
/db/index.js:
--------------------------------------------------------------------------------
1 | // ℹ️ package responsible to make the connection with mongodb
2 | // https://www.npmjs.com/package/mongoose
3 | const mongoose = require("mongoose");
4 |
5 | // ℹ️ Sets the MongoDB URI for our app to have access to it.
6 | // If no env has been set, we dynamically set it to whatever the folder name was upon the creation of the app
7 |
8 | const MONGO_URI = process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/lab-express-basic-auth";
9 |
10 | mongoose
11 | .connect(MONGO_URI)
12 | .then((x) => {
13 | console.log(`Connected to Mongo! Database name: "${x.connections[0].name}"`);
14 | })
15 | .catch((err) => {
16 | console.error("Error connecting to mongo: ", err);
17 | });
18 |
--------------------------------------------------------------------------------
/error-handling/index.js:
--------------------------------------------------------------------------------
1 | module.exports = (app) => {
2 | app.use((req, res, next) => {
3 | // this middleware runs whenever requested page is not available
4 | res.status(404).render("not-found");
5 | });
6 |
7 | app.use((err, req, res, next) => {
8 | // whenever you call next(err), this middleware will handle the error
9 | // always logs the error
10 | console.error("ERROR", req.method, req.path, err);
11 |
12 | // only render if the error ocurred before sending the response
13 | if (!res.headersSent) {
14 | res.status(500).render("error");
15 | }
16 | });
17 | };
18 |
--------------------------------------------------------------------------------
/models/User.model.js:
--------------------------------------------------------------------------------
1 | const { Schema, model } = require("mongoose");
2 |
3 | // TODO: Please make sure you edit the user model to whatever makes sense in this case
4 | const userSchema = new Schema({
5 | username: {
6 | type: String,
7 | unique: true
8 | },
9 | password: String
10 | });
11 |
12 | const User = model("User", userSchema);
13 |
14 | module.exports = User;
15 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lab-express-basic-auth",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "start": "node server.js",
7 | "dev": "nodemon server.js"
8 | },
9 | "dependencies": {
10 | "cookie-parser": "^1.4.5",
11 | "dotenv": "^8.2.0",
12 | "express": "^4.17.1",
13 | "hbs": "^4.1.1",
14 | "mongoose": "^6.1.2",
15 | "morgan": "^1.10.0",
16 | "serve-favicon": "^2.5.0"
17 | },
18 | "devDependencies": {
19 | "nodemon": "^2.0.7"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/public/images/favicon.ico:
--------------------------------------------------------------------------------
1 | h 6 � � 00 �% F ( @ ��������������������2?��2���3���2G��������������������������������1-��3���2���2���2���2���3���13��.�����������������2��3���2���1���2���2���2���2���2���2���3���2��������4��2���2���1���2���2���2���2���2���2���2���2���1���2���2���3��3g��2���2���3���3���5���5���4���1���?���5���1���2���2���2���3m��3s��1���1���M���G���c���z��Ձ��Ղ���A���y���i���-���2���1���3u��3s��1���1���L���}��։���]���o���n�����ڙ���F���2���2���1���3u��3s��1���1���:���9���H���(���N���@���b���C���N���+���2���1���3u��3u��1���1���G������{��ݜ���m������a���f������-���2���1���3u��3u��1���1���O��ܜ�������������>�������������/���2���1���3u��3u��1���1���N��ܙ���������ߔ������}������ޒ���.���2���1���3u��3o��2���2���2���3���4���,���(���.���,���1���4���2���2���2���3q��2
��3���2���1���2���2���2���2���2���2���2���2���1���2���3���1��������2+��3���2���2���2���2���2���2���2���2���3���2-��������������������2=��2���2���2���2���2���3���2A��������������������������������3Q��3���2���3W��/��������������� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� ��( @ � ��������������������������������������@��1��1[��3���3���3k��2��@��������������������������������������������������������������������B�����3=��2���3���2���3���3���3���1M���������������������������������������������������������������3��2C��2���2���2���2���2���2���2���2���3���2���2M��3 �� ��3�����������������������������������������3�����1!��2���4���2���2���2���2���2���2���2���2���1���2���3���2���0+��3��-��������������������������������*�����3+��3}��3���3���2���2���2���2���2���2���2���2���2���2���2���2���3���2���3���21����������������������������G��2��2c��3���3���2���1���2���2���2���2���2���2���2���2���2���2���2���2���1���2���3���3���2k��3��G��U�����������B��1��2_��3���3���1���1���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���1���2���3���3���1e��2��8�����U��1��3���3���2���1���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2'��D��2
��2���3���2���2���2���1���0���0���1���1���0���/���1���1���1���.���0���'���(���0���0���2���)���2���2���2���2���2���2���2���4��1��3���2���2���2���2���0���:���:���0���6���=���@���4���5���7���5���/���\���P���:���9���+���>���2���1���2���2���2���2���3���1��1��3���1���2���2���0���)���p���j���*���?��҂��ؚ���F���4��Հ��ӄ��ީ���t���`��Ӄ���R���e��ׇ������3���2���2���2���2���3���1��3��3���1���2���2���0���)���q���h������?��ԋ���]�����ٖ������[��ӂ��� �����ӆ��ֈ��ُ���)���3���1���2���2���2���2���3���1!��3��3���1���2���2���0���)���o�����ٚ��߬��ד���1��ۣ���K��֍���d���s���/���"��Մ�������)���2���1���2���2���2���2���2���3���1!��2��3���1���2���2���0���)���p���u���/���W��Տ�������ڙ���K���a��Ӄ��������Ӈ����ْ���*���5���1���2���2���2���2���3���1!��2��3���1���2���2���0���)���g���d���-���O��ҁ������P������/���1��ܞ��؛��с���w���G���[��Տ������3���2���2���2���2���3���1!��2��3���1���2���2���1���0���'���&���.������3���*������2���0������ ���:���1������0���'���)���0���2���2���2���2���2���3���1!��2��3���1���2���2���1���.���Q��Հ���F�����;���b��Ո���+���\��ݠ��؆���7���T���|���0���Q��։���#���3���2���2���2���2���3���1!��1��3���1���2���2���0���*���t�������d�������>����������C�������������چ���q�������#�����������,���1���2���2���2���2���3���1!��1��3���2���2���2���1���*���t�������e���������������@��ܝ������� ���������ӄ������Չ�����������/���2���2���2���2���2���3���1!��1��3���2���2���2���0���*���t�������f�������������ޝ��ە������� ���z������Ԋ����������ܣ�������*���2���2���2���2���2���3���1!��1��3���2���2���2���1���*���t�������e�������]����������i�������:���������{�����������D�������*���2���2���2���2���2���3���1!��1��3���2���2���2���1���)���p�������b��������������ٓ���3���������������g���a�������c���B�������+���2���2���2���2���2���3���1��1!��3���1���2���2���2���1���4���9���0���:���@���-��� ���*������=���������-���5���,���4���:���2���2���2���2���2���2���3���1!��1��2���2���2���2���2���1���1���0���1���/���(���0���3���2���4���,���1���3���2���0���2���1���0���2���2���2���2���2���2���3���2�����21��3���3���2���1���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���1���2���3���4���27�����������2%��3}��3���3���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���3���3���3}��2'��������������@�����1��2���3���3���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���3���2���3�����@�������������������� ��0��2C��4���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���1E��6�� ��������������������������������B�����2?��2���3���2���2���2���2���2���2���2���2���2���2���3���3���1C�����B��������������������������������������������@��4��3[��3���3���2���1���2���2���1���2���3���2���3_��1��@�����������������������������������������������������@�������3a��4���3���2���2���2���3���2i��8�����@����������������������������������������������������������������4��2��3{��2���2���2���2#��9����������������������������������� ( 0 ` �% ��������������������������������������������������������@�����������1U��3���3���3o��3��������@��������������������������������������������������������������������������������������������������������U��U��������1E��1���4���5���5���5���2���2a�����������@��������������������������������������������������������������������������������������������U��@��������41��3���3���5���1���2���2���2���4���5���1���2I�������� ��U�������������������������������������������������������������������������������� ��3��������2%��1���2���5���2���2���2���2���2���2���2���2���4���4���2���29��������@�� �����������������������������������������������������������������������@��������3��2���2���5���2���2���2���2���2���2���2���2���2���2���2���2���5���2���3���2%��������@�� �����������������������������������������������������������3��������.��2{��2���6���3���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���5���2���2���,��������3��������������������������������������������������@�����������3e��2���5���3���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���3���5���2���2u��@ ��������@��������������������������������������@�� ��������4U��3���5���4���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���3���5���2���1c�����������@�������������������������� ��U��������4A��2���4���4���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���4���5���2���3K��������U��U�����������������@��������33��2���3���5���1���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���4���4���2���0;��������@�����������U�����.��3���2���5���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���5���2���1���5#����� �����U�����15��2���6���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���5���2���3U�����U�����3��2���5���2���2���2���2���2���2���1���5���5���1���2���2���7���3���6���4���1���2���1���4���6���0���7���;���;���7���2���7���2���1���4���8���2���2���2���2���2���2���2���2���4���2���6!��������2Q��4���2���2���2���2���2���2���1���4���$���&���4���1���3������.������.���3���1���4���+������;������ ��� ������1������1���6���1��� ���3���2���2���2���2���2���2���2���2���4���3[��������2[��4���2���2���2���2���2���2���4���)���Q���N���)���4���.���X���?���Z���<���4���:���2���B���^��� ���M��ӊ��ԍ���f���6���Z���5���)���%���m���2���1���2���2���2���2���2���2���2���4���1_��������1Y��4���1���2���2���2���2���0���>��� ��ܧ��ٞ��� ���?��� ������c��ܨ��Փ��� ���0��� ��ܨ��ٝ���b������߰��ޭ��т���a�������(��� �����ۦ��� ���8���2���2���2���2���2���2���2���4���1]��������3[��4���1���2���2���2���2���0���>��� ��ݫ��ڢ��� ���A��� �������g���u�������K���a���V�������X������Փ��� ��� ��� ���l������� ��������� ���3���3���2���2���2���2���2���2���2���4���1_��������3[��4���2���2���2���2���2���0���>��� ��ܩ��؛��� ���'��� ������x��� ����������ݧ������������������G���)���B��� ���l�����ۦ������ ���/���5���1���2���2���2���2���2���2���2���4���1_��������3[��4���1���2���2���2���2���0���>��� ��ܧ������ެ�������������r��� ��ܧ��ڢ��� �����Ր���+�������I���#���:������R����������� ���9���6���1���2���2���2���2���2���2���2���2���4���1_��������3[��4���1���2���2���2���2���0���>��� ��ܩ������Y���t���g�������v��� ���m������:�������D���A�������J���3���C������c���������с��� ���?���1���2���2���2���2���2���2���2���2���4���1_��������2[��4���1���2���2���2���2���0���>��� ��ܩ��ؚ��� ������ ������w��� ���%��߰�����ޮ��� ���$�������l��� ��� ��� ���o������K������Ѐ��� ���;���1���2���2���2���2���2���2���2���4���1_��������2[��4���1���2���2���2���2���0���>��� ��ޭ��ۥ��� ���E����������y��� ��� ��ф�������q������ ��֖������Ր��Ց���l���f������� ���Q������с��� ���8���2���2���2���2���2���2���2���4���1_��������2[��4���1���2���2���2���2���1���7������p���m������7���1���}���Q���'���4���I��Ԏ���5���4���>�����҅��߰��߱��҄���E���}���:��� ���c��҇������4���2���2���2���2���2���2���2���4���1_��������2[��4���1���2���2���2���2���2���0���8��� ��� ���2���/������ ���+���6������ ��� ���9���)��� ��� ��� ��� ��� ��� ��� ��� ���1���?��� ��� ���9���1���2���2���2���2���2���2���2���4���1_��������2[��4���1���2���2���2���2���2���4���*���N���g���<���8���c���R���/���(���]���d���?��� ���6���q���q���>������<���M���b���?���4��� ���b���X���!���5���2���2���2���2���2���2���2���4���1_��������2]��4���1���2���2���2���2���1���>��� ��ݪ�������t���Y���������� ��Ԏ����������� ��҈������������������҈��� ��ܧ�������h��� ���~�����������
���3���3���2���2���2���2���2���2���4���1_��������2]��4���2���2���2���2���2���0���@��� ��߱�������y���\���������� �����������`��� ����������י��֖����������� ��ݬ�������j��� ���������������;���*���5���2���2���2���2���2���2���4���1_��������2]��4���2���2���2���2���2���1���?��� ��ޮ�������w���[���������ט������ۥ��� ���k����������� ��� �����������?��ڣ�������N��҉���������������5���,���5���2���2���2���2���2���2���4���1_��������2]��4���2���2���2���2���2���0���?��� ��ޯ�������x���`��������������������������r���������� ��� ����������X��ڢ�������P�������������������+���-���5���2���2���2���2���2���2���4���1_��������2]��4���2���2���2���2���2���0���?��� ��ޯ�������x���]����������у����������ۦ���Y���������� ��� ����������V��ۥ������ݩ�������q�����������(���-���5���2���2���2���2���2���2���4���1_��������1]��4���2���2���2���2���2���1���?��� ��ޮ�������w���Z������߱��� ��� �����������5����������� ��� �����������:��ۤ��������������� �����������)���-���5���2���2���2���2���2���2���4���1_��������1]��4���2���2���2���2���2���0���@��� ��߲�������y���_����������҆����������߰��� ����������߱��߰����������� ��ܨ����������у��� �����������)���-���5���2���2���2���2���2���2���4���1_��������1]��4���2���2���2���2���2���1���>��� ��ۥ�������s���V�����������������������L��� ���v�������������������w��� ��҈���������� ��� �����������*���.���4���2���2���2���2���2���2���4���1]��������1]��4���1���2���2���2���2���2���2���/���=���L���8���-���@���Y���`���J��� ���!���:��� ��� ���T���S��� ��� ���8���%���M������.���1���B���H���2���2���2���2���2���2���2���2���2���4���1]��������2a��5���2���2���2���2���2���2���2���3���+������/���2���%������������8���6���0���:���2���������3���9���1���3������3���4���2���(���"���2���2���2���2���2���2���2���2���2���4���2a��������1/��2���3���2���2���2���2���2���2���1���5���9���3���2���7���9���9���8���3���1���2���1���5���9���9���5���1���2���3���8���4���1���2���6���7���2���2���2���2���2���2���2���2���3���3���37����� �����3k��4���4���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���4���5���2{�����������������3A��2���5���4���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���4���5���2���3G�����������������U��������2g��2���6���3���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���3���6���2���2e�������� �����������������@��������9 ��1w��3���5���3���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���3���5���2���3y��9 ��������@��������������������������3��������.��3���2���6���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���5���2���2���5��������3����������������������������������� ��@��������6!��3���2���5���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���5���2���2���0%��������@�� �������������������������������������������� ��@��������33��2���3���5���1���2���2���2���2���2���2���2���2���2���2���2���2���2���2���2���5���4���2���19��������@��U��������������������������������������������������������U��U��������4A��2���4���4���2���2���2���2���2���2���2���2���2���2���2���2���4���5���3���1I�������� ��U��������������������������������������������������������������������@�����������4U��2���5���4���2���2���2���2���2���2���2���2���3���5���2���2a�����������@��������������������������������������������������������������������������������@�������� ��3e��3���5���3���2���2���2���2���3���5���2���3s��9 ��������@��������������������������������������������������������������������������������������������3��������7��2{��3���6���3���2���6���2���2���5��������3����������������������������������������������������������������������������������������������������� ��3��������5��3���2���2���3���0%��������@�� ��������������������������������������������������� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� ��
--------------------------------------------------------------------------------
/public/js/script.js:
--------------------------------------------------------------------------------
1 | document.addEventListener(
2 | "DOMContentLoaded",
3 | () => {
4 | console.log("lab-express-basic-auth JS imported successfully!");
5 | },
6 | false
7 | );
8 |
--------------------------------------------------------------------------------
/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
9 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # LAB | Express Basic Auth
4 |
5 |
6 |
7 | ## Introduction
8 |
9 |
10 |
11 | In this lab, you are going to reinforce the knowledge of how to create basic authorization and authentication in a web app.
12 |
13 | 
14 |
15 | ## Requirements
16 |
17 | - Fork this repo
18 | - Clone this repo
19 |
20 | ## Submission
21 |
22 | - Upon completion, run the following commands:
23 |
24 | ```
25 | git add .
26 | git commit -m "done"
27 | git push origin master
28 | ```
29 |
30 | - Create Pull Request so your TAs can check up your work.
31 |
32 |
33 |
34 | ## Instructions
35 |
36 | _In this lab, you literally have to recreate materials your instructors went through in the class. The point is not to blindly copy-paste them, but the opposite of that: to go once again, step by step through the process of registering users and authenticating them in the web app. Try to target all the weak spots, everything you missed to grasp during the lecture time, so you can ask your instructors and assistants to push you through the learning process._
37 |
38 |
39 |
40 | ### Iteration 0 | Initialize the project
41 |
42 | After forking and cloning the project, you will have to install all the dependencies:
43 |
44 | ```sh
45 | $ cd lab-express-basic-auth
46 | $ npm install
47 | ```
48 |
49 | Now you are ready to start 🚀
50 |
51 |
52 |
53 | ## Iteration 1 | Sign Up
54 |
55 | We have to create the _signup_ feature - the goal is to enable our users to register in our application. The users have to provide the following information:
56 |
57 | - **username**: must be unique in our application and will identify each user
58 | - **password**: must be encrypted (you can use the `bcryptjs` npm package).
59 |
60 | To complete this first iteration, you have to create the model as well as the corresponding routes and views.
61 |
62 |
63 |
64 | ## Iteration 2 | Login
65 |
66 | Once the user has signed up, he/she should be able to authenticate themselves. This means the user should be able to log in to the application. Your assignment in this iteration is to create corresponding routes as well as the views to let them log in to the application.
67 |
68 | As you know, it is not enough just to allow users to log in. Users should be able to maintain their "presence" in the application (stay logged in when going from a page to a page, after the refresh), and for that, there should be the user(s) in the session. You have learned that you can use the `express-session` and `connect-mongo` npm packages to create a session.
69 |
70 |
71 |
72 | ## Iteration 3 | Protected Routes
73 |
74 | At this point, you have implemented the basic authentication in this application. Your next assignment is to create the authentication middleware and protect some routes. Refresher: users can't visit these routes unless they are authenticated (logged in and exist in the session).
75 |
76 | Let's create two different routes protected by authentication:
77 |
78 | - `/main` - Add a funny picture of a cat and a link back to the home page
79 | - `/private` - Add your favorite `gif` and an `
nodemon
installed on your machine:
148 |
149 | ```bash
150 | npm install -g nodemon
151 | ```
152 |
153 | This will install nodemon globally on your system, making it available to all of your projects.
154 |
155 | Welcome to {{title}}
3 | -------------------------------------------------------------------------------- /views/layout.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |