UserManagement Report
UserManagement Report
<Report>
Introduction:
This report provides an overview of the development process and technologies used in building a
User Management System (UMS). A UMS is a crucial component for managing user accounts,
authentication, and authorization within web applications. The system allows administrators to
create, update, and delete user accounts, as well as define access permissions and roles.
Technologies Used:
1. HTML
2. CSS
3. JavaScript
4. Node.js:
5. Express.js:
6. EJS
7. MongoDB:
Development Process:
1. Planning and Design: The development process begins with defining the requirements and
functionalities of the User Management System. Wireframes and mockups are created to visualize
the user interface and workflow. The design should consider usability, security, and scalability
aspects.
2. Frontend Development: HTML, CSS, and JavaScript are used to implement the frontend
components of the UMS, including user registration forms, login pages, user profile views, and
administrative dashboards. Frontend development focuses on creating an intuitive and user-friendly
interface.
3. Backend Development: Node.js and Express.js are employed to build the backend infrastructure
of the UMS. This involves setting up routes for handling user authentication, account management,
and authorization. Middleware functions may be used for tasks such as input validation,
authentication checks, and error handling.
4. Database Integration: MongoDB is used as the backend database for storing user-related data.
MongoDB collections are created to store user accounts, authentication tokens, and access control
lists. Mongoose, an Object Data Modeling (ODM) library for MongoDB, may be used to facilitate data
manipulation and schema validation.
5. Integration and Testing: Frontend and backend components are integrated to form a cohesive
User Management System. Testing is performed to ensure functionality, security, and performance.
Unit tests, integration tests, and end-to-end tests may be conducted to validate the system's
behavior under various scenarios.
Conclusion:
The User Management System is a critical component of web applications, providing functionality
for user registration, authentication, and authorization. By leveraging technologies such as HTML,
CSS, JavaScript, Node.js, Express.js, EJS, and MongoDB, a robust and scalable UMS can be developed
to meet the needs of modern web applications, ensuring secure and efficient user management
capabilities.
body {
font-size: .875rem;
.feather {
width: 16px;
height: 16px;
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
/* rtl:raw:
right: 0;
*/
bottom: 0;
/* rtl:remove */
left: 0;
.sidebar {
top: 5rem;
.sidebar-sticky {
overflow-x: hidden;
.sidebar .nav-link {
font-weight: 500;
color: #333;
margin-right: 4px;
color: #727272;
.sidebar .nav-link.active {
color: #2470dc;
}
color: inherit;
.sidebar-heading {
font-size: .75rem;
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
.navbar .navbar-toggler {
top: .25rem;
right: 1rem;
}
.navbar .form-control {
color: white;
opacity: 1; /* Firefox */
.form-control-dark {
color: #fff;
.form-control-dark:focus {
border-color: transparent;
module.exports = connectDB;
/**
* GET /
* Homepage
*/
exports.homepage = async (req, res) => {
// Remove
// const messages = await req.consumeFlash('info');
// Use this instead
const messages = await req.flash("info");
const locals = {
title: "NodeJs",
description: "Free NodeJs User Management System",
};
try {
const customers = await Customer.aggregate([{ $sort: { createdAt: -1 } }])
.skip(perPage * page - perPage)
.limit(perPage)
.exec();
// Count is deprecated. Use countDocuments({}) or estimatedDocumentCount()
// const count = await Customer.count();
const count = await Customer.countDocuments({});
res.render("index", {
locals,
customers,
current: page,
pages: Math.ceil(count / perPage),
messages,
});
} catch (error) {
console.log(error);
}
};
// exports.homepage = async (req, res) => {
// const messages = await req.consumeFlash('info');
// const locals = {
// title: 'NodeJs',
// description: 'Free NodeJs User Management System'
// }
// try {
// const customers = await Customer.find({}).limit(22);
// res.render('index', { locals, messages, customers } );
// } catch (error) {
// console.log(error);
// }
// }
/**
* GET /
* About
*/
exports.about = async (req, res) => {
const locals = {
title: "About",
description: "Free NodeJs User Management System",
};
try {
res.render("about", locals);
} catch (error) {
console.log(error);
}
};
/**
* GET /
* New Customer Form
*/
exports.addCustomer = async (req, res) => {
const locals = {
title: "Add New Customer - NodeJs",
description: "Free NodeJs User Management System",
};
res.render("customer/add", locals);
};
/**
* POST /
* Create New Customer
*/
exports.postCustomer = async (req, res) => {
console.log(req.body);
try {
await Customer.create(newCustomer);
await req.flash("info", "New customer has been added.");
res.redirect("/");
} catch (error) {
console.log(error);
}
};
/**
* GET /
* Customer Data
*/
exports.view = async (req, res) => {
try {
const customer = await Customer.findOne({ _id: req.params.id });
const locals = {
title: "View Customer Data",
description: "Free NodeJs User Management System",
};
res.render("customer/view", {
locals,
customer,
});
} catch (error) {
console.log(error);
}
};
/**
* GET /
* Edit Customer Data
*/
exports.edit = async (req, res) => {
try {
const customer = await Customer.findOne({ _id: req.params.id });
const locals = {
title: "Edit Customer Data",
description: "Free NodeJs User Management System",
};
res.render("customer/edit", {
locals,
customer,
});
} catch (error) {
console.log(error);
}
};
/**
* GET /
* Update Customer Data
*/
exports.editPost = async (req, res) => {
try {
await Customer.findByIdAndUpdate(req.params.id, {
firstName: req.body.firstName,
lastName: req.body.lastName,
tel: req.body.tel,
email: req.body.email,
details: req.body.details,
updatedAt: Date.now(),
});
await res.redirect(`/edit/${req.params.id}`);
console.log("redirected");
} catch (error) {
console.log(error);
}
};
/**
* Delete /
* Delete Customer Data
*/
exports.deleteCustomer = async (req, res) => {
try {
await Customer.deleteOne({ _id: req.params.id });
res.redirect("/");
} catch (error) {
console.log(error);
}
};
/**
* Get /
* Search Customer Data
*/
exports.searchCustomers = async (req, res) => {
const locals = {
title: "Search Customer Data",
description: "Free NodeJs User Management System",
};
try {
let searchTerm = req.body.searchTerm;
const searchNoSpecialChar = searchTerm.replace(/[^a-zA-Z0-9 ]/g, "");
res.render("search", {
customers,
locals,
});
} catch (error) {
console.log(error);
}
};
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
tel: {
type: String,
required: true
},
email: {
type: String,
required: true
},
details: {
type: String,
required: true
},
createdAt: {
type: Date,
default: Date.now()
},
updatedAt: {
type: Date,
default: Date.now()
});
/**
* Customer Routes
*/
router.get('/', customerController.homepage);
router.get('/about', customerController.about);
router.get('/add', customerController.addCustomer);
router.post('/add', customerController.postCustomer);
router.get('/view/:id', customerController.view);
router.get('/edit/:id', customerController.edit);
router.put('/edit/:id', customerController.editPost);
router.delete('/edit/:id', customerController.deleteCustomer);
router.post('/search', customerController.searchCustomers);
module.exports = router;
File Name:- add.ejs
file location:- user/-management/views/customer/add.ejs:-
Code:
</div>
<div class="col">
<label for="lastName">Last Name</label>
<input type="text" class="form-control" id="lastName" name="lastName" value=""
placeholder="Last Name" required>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
</ol>
</nav>
</div>
</div>
</div>
</div>
<div class="col">
</div>
<div class="col">
<label for="lastName">Last Name</label>
</div>
</div>
<div class="col">
<label for="tel">Telephone</label>
</div>
<div class="col">
<label for="email">Email</label>
</div>
</div>
</div>
</div>
</form>
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<p>
This will remove the customer record of <b class="fw-bold"><%= customer.firstName %> <%=
customer.lastName %></b><br/>
</p>
</div>
<div class="modal-footer">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
</ol>
</nav>
</div>
</div>
</div>
</div>
<ul class="list-group">
<li class="list-group-item">
<div class="row">
</div>
</li>
<li class="list-group-item">
<div class="row">
</div>
</li>
<li class="list-group-item">
<div class="row">
</div>
</li>
<li class="list-group-item">
<div class="row">
</div>
</li>
<li class="list-group-item">
<div class="row">
</div>
</li>
<li class="list-group-item">
<div class="row">
</div>
</li>
</ul>
File Name:- main.ejs
file location:- user/-management/views/layouts/main.ejs:-
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= locals.title %></title>
<meta name="description" content="<%= locals.description %>">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<%- include('../partials/sidebar.ejs') %>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-
oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-
mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD"
crossorigin="anonymous"></script>
</body>
</html>
File Name:- header.ejs
file location:- user/-management/views/partials/add.ejs:-
Code:
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3 fs-6" href="/"
>User Management System</a
>
<button
class="navbar-toggler position-absolute d-md-none collapsed"
type="button"
data-bs-toggle="collapse"
data-bs-target="#sidebarMenu"
aria-controls="sidebarMenu"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<form
class="nav col-12 col-md-auto flex-fill mb-2 justify-content-center mb-md-0"
role="search"
method="POST"
action="/search"
>
<input
type="search"
name="searchTerm"
class="form-control form-control-dark w-100 rounded-0 border-0"
placeholder="Search..."
aria-label="Search"
/>
</form>
</header>
<h1>404</h1>
<div
class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2
mb-3 border-bottom"
>
<h1 class="h2">About</h1>
</div>
<div class="pt-3">
<p>This is a simple user management system.</p>
</div>
File Name:- index.ejs
file location:- user/-management/views /index.ejs:-
Code:
<h1 class="h2">Dashboard</h1>
</div>
</div>
</div>
</div>
<% }) %>
<div class="table-responsive">
<thead>
<tr>
<th scope="col">Email</th>
</tr>
</thead>
<tbody>
<tr class="align-middle">
<td class="text-end">
</a>
</a>
</form>
</div>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
<% } %>
<% } %>
<% } %>
<% } %>
<% } %>
<% } %>
</ul>
</nav>
<% } %>
<div class="table-responsive">
<% if (customers != "") { %>
</div>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
// Connect to Database
// connectDB();
mongoose.connect("mongodb://localhost:27017/UserDataManagement")
.then(() => {
console.log("DataBase Connected");
})
.catch((e) => {
console.log(e);
console.log("DataBase Cont Connected");
});
// Static Files
app.use(express.static('public'));
// Express Session
app.use(
session({
secret: 'secret',
resave: false,
saveUninitialized: true,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 7, // 1 week
}
})
);
// Flash Messages
app.use(flash({ sessionKeyName: 'flashMessage' }));
// Templating Engine
app.use(expressLayout);
app.set('layout', './layouts/main');
app.set('view engine', 'ejs');
// Routes
app.use('/', require('./server/routes/customer'))
// Handle 404
app.get('*', (req, res) => {
res.status(404).render('404');
});
app.listen(port, ()=> {
console.log(`App listeing on port ${port}`)
});
"name": "nodejs_user_management",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"connect-flash": "^0.1.1",
"dotenv": "^16.0.3",
"ejs": "^3.1.8",
"express": "^4.18.2",
"express-ejs-layouts": "^2.5.1",
"express-session": "^1.17.3",
"method-override": "^3.0.0",
"mongoose": "^7.6.8"
},
"devDependencies": {
"nodemon": "^3.0.3"
You need:
Installation:-
To install and run this project - install dependencies using npm and then start your server:
```
npm install
npm start
```