Merge branch 'main' of https://github.com/Newtbot/MP
This commit is contained in:
commit
7fbd9ae2e7
30
Sean/inusers.js
Normal file
30
Sean/inusers.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// inusers.js
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// Middleware to check if the user is authenticated
|
||||||
|
function isAuthenticated(req, res, next) {
|
||||||
|
if (req.session && req.session.authenticated) {
|
||||||
|
return next();
|
||||||
|
} else {
|
||||||
|
res.redirect('/login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InUsers route (renders the InUsers tab)
|
||||||
|
router.get('/', isAuthenticated, (req, res) => {
|
||||||
|
res.render('inusers');
|
||||||
|
});
|
||||||
|
|
||||||
|
// User Data route
|
||||||
|
router.get('/userdata', isAuthenticated, (req, res) => {
|
||||||
|
res.render('user-data');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Edit User Data route
|
||||||
|
router.get('/edituserdata', isAuthenticated, (req, res) => {
|
||||||
|
res.render('edit-user-data');
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -5,13 +5,14 @@ const bodyParser = require('body-parser');
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
require('dotenv').config()
|
require('dotenv').config();
|
||||||
|
|
||||||
const mysqlConfig = {
|
const mysqlConfig = {
|
||||||
host: process.env.host,
|
host: process.env.host,
|
||||||
user: process.env.user,
|
user: process.env.user,
|
||||||
password: process.env.password,
|
password: process.env.password,
|
||||||
database: process.env.database,
|
database: process.env.database,
|
||||||
|
timezone: 'Z', // Set the timezone to UTC
|
||||||
};
|
};
|
||||||
|
|
||||||
const mysqlConnection = mysql.createConnection(mysqlConfig);
|
const mysqlConnection = mysql.createConnection(mysqlConfig);
|
||||||
@ -24,7 +25,6 @@ app.get('/login', (req, res) => {
|
|||||||
res.render('login');
|
res.render('login');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if the user is authenticated before accessing certain routes
|
|
||||||
function isAuthenticated(req, res, next) {
|
function isAuthenticated(req, res, next) {
|
||||||
if (req.session && req.session.authenticated) {
|
if (req.session && req.session.authenticated) {
|
||||||
return next();
|
return next();
|
||||||
@ -33,41 +33,91 @@ function isAuthenticated(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login route
|
|
||||||
app.post('/login', (req, res) => {
|
app.post('/login', (req, res) => {
|
||||||
let { username, password } = req.body;
|
let { username, password } = req.body;
|
||||||
|
|
||||||
// Trim whitespace
|
|
||||||
username = username.trim();
|
username = username.trim();
|
||||||
|
|
||||||
// Validate username and password against MySQL
|
const loginSql = 'SELECT * FROM users WHERE username = ? AND password = ?';
|
||||||
const sql = 'SELECT * FROM users WHERE username = ? AND password = ?';
|
const updateLastLoginSql = 'UPDATE users SET lastLogin = CURRENT_TIMESTAMP WHERE username = ?';
|
||||||
mysqlConnection.query(sql, [username, password], (error, results) => {
|
|
||||||
|
// Check credentials and retrieve user information
|
||||||
|
const connection = mysql.createConnection(mysqlConfig);
|
||||||
|
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
connection.query(loginSql, [username, password], (error, results) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Error executing login query:', error);
|
console.error('Error executing login query:', error);
|
||||||
res.status(500).send('Internal Server Error');
|
res.status(500).send('Internal Server Error');
|
||||||
|
connection.end(); // Close the connection in case of an error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('SQL Query:', sql, [username, password]);
|
|
||||||
console.log('Query Results:', results);
|
|
||||||
|
|
||||||
if (results.length === 0) {
|
if (results.length === 0) {
|
||||||
res.status(401).send('Invalid username or password');
|
res.status(401).send('Invalid username or password');
|
||||||
|
connection.end(); // Close the connection when not needed anymore
|
||||||
} else {
|
} else {
|
||||||
|
// Update lastLogin field for the user
|
||||||
|
connection.query(updateLastLoginSql, [username], (updateError, updateResults) => {
|
||||||
|
if (updateError) {
|
||||||
|
console.error('Error updating lastLogin:', updateError);
|
||||||
|
res.status(500).send('Internal Server Error');
|
||||||
|
connection.end(); // Close the connection in case of an error
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the update affected any rows
|
||||||
|
if (updateResults.affectedRows > 0) {
|
||||||
// Set session data for authentication
|
// Set session data for authentication
|
||||||
req.session.authenticated = true;
|
req.session.authenticated = true;
|
||||||
req.session.username = username;
|
req.session.username = username;
|
||||||
|
|
||||||
// Redirect to the home page or any other protected route
|
// Redirect to the home page or any other protected route
|
||||||
res.redirect('/home');
|
res.redirect('/home');
|
||||||
|
} else {
|
||||||
|
res.status(500).send('Error updating lastLogin. No rows affected.');
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.end(); // Close the connection when not needed anymore
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Home route (protected by authentication)
|
// Update your /home route to retrieve the overall last 10 logins for all users
|
||||||
app.get('/home', isAuthenticated, (req, res) => {
|
app.get('/home', isAuthenticated, (req, res) => {
|
||||||
res.render('home', { username: req.session.username });
|
// Retrieve the overall last 10 logins for all users
|
||||||
|
const loginsQuery = 'SELECT username, lastLogin FROM users ORDER BY lastLogin DESC LIMIT 10';
|
||||||
|
|
||||||
|
mysqlConnection.query(loginsQuery, (error, loginResults) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('Error executing login logs query:', error);
|
||||||
|
res.status(500).send('Internal Server Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log the results on the server side
|
||||||
|
console.log('Login Logs on Server:', loginResults);
|
||||||
|
|
||||||
|
// Render the home page with login logs data
|
||||||
|
res.render('home', { username: req.session.username, loginLogs: loginResults });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/inusers', isAuthenticated, (req, res) => {
|
||||||
|
// Fetch all user data from the database
|
||||||
|
const allUsersQuery = 'SELECT * FROM users';
|
||||||
|
|
||||||
|
mysqlConnection.query(allUsersQuery, (error, allUsers) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching all users:', error);
|
||||||
|
res.status(500).send('Internal Server Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render the inusers page with all user data
|
||||||
|
res.render('inusers', { allUsers: allUsers });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(express.static('views'));
|
app.use(express.static('views'));
|
||||||
@ -75,5 +125,3 @@ app.use(express.static('views'));
|
|||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Server is running on port ${PORT}`);
|
console.log(`Server is running on port ${PORT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
30
Sean/views/allusers.ejs
Normal file
30
Sean/views/allusers.ejs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>All Users</title>
|
||||||
|
<!-- Add any additional styles or dependencies here -->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>All Users</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Username</th>
|
||||||
|
<!-- Add additional columns as needed -->
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% for (let i = 0; i < users.length; i++) { %>
|
||||||
|
<tr>
|
||||||
|
<td><%= users[i].username %></td>
|
||||||
|
<!-- Add additional columns as needed -->
|
||||||
|
</tr>
|
||||||
|
<% } %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,270 +1,162 @@
|
|||||||
|
<!-- views/home.ejs -->
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible"
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
content="IE=edge">
|
<title>Home</title>
|
||||||
<meta name="viewport"
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
|
||||||
content="width=device-width,
|
<style>
|
||||||
initial-scale=1.0">
|
body {
|
||||||
<title>GeeksForGeeks</title>
|
margin: 0;
|
||||||
<link rel="stylesheet"
|
font-family: 'Arial', sans-serif;
|
||||||
href="style.css">
|
}
|
||||||
<link rel="stylesheet"
|
|
||||||
href="responsive.css">
|
#sidebar {
|
||||||
,
|
height: 100%;
|
||||||
|
width: 250px;
|
||||||
|
position: fixed;
|
||||||
|
background-color: #333;
|
||||||
|
padding-top: 60px;
|
||||||
|
transition: 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar img {
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar a {
|
||||||
|
padding: 10px 15px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 18px;
|
||||||
|
color: white;
|
||||||
|
display: block;
|
||||||
|
transition: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar a:hover {
|
||||||
|
background-color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
margin-left: 250px;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
#sidebar {
|
||||||
|
width: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
left: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse span {
|
||||||
|
display: block;
|
||||||
|
background: white;
|
||||||
|
height: 5px;
|
||||||
|
width: 30px;
|
||||||
|
margin: 6px auto;
|
||||||
|
transition: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse:hover span:nth-child(1) {
|
||||||
|
transform: rotate(-45deg) translate(-5px, 6px);
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse:hover span:nth-child(2) {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse:hover span:nth-child(3) {
|
||||||
|
transform: rotate(45deg) translate(-5px, -6px);
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 80%;
|
||||||
|
margin: 20px 0;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th, td {
|
||||||
|
border: 1px solid #dddddd;
|
||||||
|
text-align: left;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<div id="sidebar">
|
||||||
<header>
|
<img src="LOGO.PNG" alt="Custom Image">
|
||||||
|
<div id="sidebarCollapse">
|
||||||
<div class="logosec">
|
<span></span>
|
||||||
<div class="logo">Eco Saver</div>
|
<span></span>
|
||||||
<img src=
|
<span></span>
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210182541/Untitled-design-(30).png"
|
</div>
|
||||||
class="icn menuicn"
|
<a href="/inusers">In-House Users</a>
|
||||||
id="menuicn"
|
<a href="#">Users</a>
|
||||||
alt="menu-icon">
|
<a href="#">Data Analysis</a>
|
||||||
|
<a href="#">Logout</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="searchbar">
|
<div id="content">
|
||||||
<input type="text"
|
<h2>Welcome to the Home Page, <%= username %>!</h2>
|
||||||
placeholder="Search">
|
<h3>Last 10 Logins:</h3>
|
||||||
<div class="searchbtn">
|
<table>
|
||||||
<img src=
|
<thead>
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210180758/Untitled-design-(28).png"
|
<tr>
|
||||||
class="icn srchicn"
|
<th>Username</th>
|
||||||
alt="search-icon">
|
<th>Last Login Time</th>
|
||||||
</div>
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% loginLogs.forEach(log => { %>
|
||||||
|
<tr>
|
||||||
|
<td><%= log.username %></td>
|
||||||
|
<td><%= new Date(log.lastLogin).toLocaleString('en-US', { timeZone: 'Asia/Singapore' }) %></td>
|
||||||
|
</tr>
|
||||||
|
<% }); %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById('sidebarCollapse').addEventListener('click', function () {
|
||||||
|
document.getElementById('sidebar').style.width = (document.getElementById('sidebar').style.width === '250px') ? '0' : '250px';
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="message">
|
|
||||||
<div class="circle"></div>
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210183322/8.png"
|
|
||||||
class="icn"
|
|
||||||
alt="">
|
|
||||||
<div class="dp">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210180014/profile-removebg-preview.png"
|
|
||||||
class="dpicn"
|
|
||||||
alt="dp">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="main-container">
|
|
||||||
<div class="navcontainer">
|
|
||||||
<nav class="nav">
|
|
||||||
<div class="nav-upper-options">
|
|
||||||
<div class="nav-option option1">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210182148/Untitled-design-(29).png"
|
|
||||||
class="nav-img"
|
|
||||||
alt="dashboard">
|
|
||||||
<h3> Dashboard</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="option2 nav-option">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210183322/9.png"
|
|
||||||
class="nav-img"
|
|
||||||
alt="articles">
|
|
||||||
<h3> Articles</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="nav-option option3">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210183320/5.png"
|
|
||||||
class="nav-img"
|
|
||||||
alt="report">
|
|
||||||
<h3> Report</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="nav-option option4">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210183321/6.png"
|
|
||||||
class="nav-img"
|
|
||||||
alt="institution">
|
|
||||||
<h3> Institution</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="nav-option option5">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210183323/10.png"
|
|
||||||
class="nav-img"
|
|
||||||
alt="blog">
|
|
||||||
<h3> Profile</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="nav-option option6">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210183320/4.png"
|
|
||||||
class="nav-img"
|
|
||||||
alt="settings">
|
|
||||||
<h3> Settings</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="nav-option logout">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210183321/7.png"
|
|
||||||
class="nav-img"
|
|
||||||
alt="logout">
|
|
||||||
<h3>Logout</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
<div class="main">
|
|
||||||
|
|
||||||
<div class="searchbar2">
|
|
||||||
<input type="text"
|
|
||||||
name=""
|
|
||||||
id=""
|
|
||||||
placeholder="Search">
|
|
||||||
<div class="searchbtn">
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210180758/Untitled-design-(28).png"
|
|
||||||
class="icn srchicn"
|
|
||||||
alt="search-button">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="box-container">
|
|
||||||
|
|
||||||
<div class="box box1">
|
|
||||||
<div class="text">
|
|
||||||
<h2 class="topic-heading">60.5k</h2>
|
|
||||||
<h2 class="topic">Article Views</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210184645/Untitled-design-(31).png"
|
|
||||||
alt="Views">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="box box2">
|
|
||||||
<div class="text">
|
|
||||||
<h2 class="topic-heading">150</h2>
|
|
||||||
<h2 class="topic">Likes</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210185030/14.png"
|
|
||||||
alt="likes">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="box box3">
|
|
||||||
<div class="text">
|
|
||||||
<h2 class="topic-heading">320</h2>
|
|
||||||
<h2 class="topic">Comments</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210184645/Untitled-design-(32).png"
|
|
||||||
alt="comments">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="box box4">
|
|
||||||
<div class="text">
|
|
||||||
<h2 class="topic-heading">70</h2>
|
|
||||||
<h2 class="topic">Published</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<img src=
|
|
||||||
"https://media.geeksforgeeks.org/wp-content/uploads/20221210185029/13.png" alt="published">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="report-container">
|
|
||||||
<div class="report-header">
|
|
||||||
<h1 class="recent-Articles">Recent Articles</h1>
|
|
||||||
<button class="view">View All</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="report-body">
|
|
||||||
<div class="report-topic-heading">
|
|
||||||
<h3 class="t-op">Article</h3>
|
|
||||||
<h3 class="t-op">Views</h3>
|
|
||||||
<h3 class="t-op">Comments</h3>
|
|
||||||
<h3 class="t-op">Status</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="items">
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 73</h3>
|
|
||||||
<h3 class="t-op-nextlvl">2.9k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">210</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 72</h3>
|
|
||||||
<h3 class="t-op-nextlvl">1.5k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">360</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 71</h3>
|
|
||||||
<h3 class="t-op-nextlvl">1.1k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">150</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 70</h3>
|
|
||||||
<h3 class="t-op-nextlvl">1.2k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">420</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 69</h3>
|
|
||||||
<h3 class="t-op-nextlvl">2.6k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">190</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 68</h3>
|
|
||||||
<h3 class="t-op-nextlvl">1.9k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">390</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 67</h3>
|
|
||||||
<h3 class="t-op-nextlvl">1.2k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">580</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 66</h3>
|
|
||||||
<h3 class="t-op-nextlvl">3.6k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">160</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item1">
|
|
||||||
<h3 class="t-op-nextlvl">Article 65</h3>
|
|
||||||
<h3 class="t-op-nextlvl">1.3k</h3>
|
|
||||||
<h3 class="t-op-nextlvl">220</h3>
|
|
||||||
<h3 class="t-op-nextlvl label-tag">Published</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="index.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,28 +1,64 @@
|
|||||||
let menuicn = document.querySelector(".menuicn");
|
const express = require('express');
|
||||||
let nav = document.querySelector(".navcontainer");
|
const router = express.Router();
|
||||||
|
const mysql = require('mysql');
|
||||||
|
|
||||||
menuicn.addEventListener("click", () => {
|
// Replace with your MySQL connection details
|
||||||
nav.classList.toggle("navclose");
|
const mysqlConfig = {
|
||||||
})
|
host: process.env.host,
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
user: process.env.user,
|
||||||
// Fetch recent user logins from your server
|
password: process.env.password,
|
||||||
fetch('/api/recentUserLogins')
|
database: process.env.database,
|
||||||
.then(response => response.json())
|
timezone: 'Z', // Set the timezone to UTC
|
||||||
.then(userLogins => {
|
};
|
||||||
// Populate the recent user logins section
|
|
||||||
const itemsContainer = document.querySelector('.items');
|
|
||||||
|
|
||||||
userLogins.forEach(userLogin => {
|
const mysqlConnection = mysql.createConnection(mysqlConfig);
|
||||||
const item = document.createElement('div');
|
|
||||||
item.classList.add('item1');
|
// Middleware to check if the user is authenticated
|
||||||
item.innerHTML = `
|
function isAuthenticated(req, res, next) {
|
||||||
<h3 class="t-op-nextlvl">${userLogin.username}</h3>
|
if (req.session && req.session.authenticated) {
|
||||||
<h3 class="t-op-nextlvl">${userLogin.name}</h3>
|
return next();
|
||||||
<h3 class="t-op-nextlvl">${userLogin.email}</h3>
|
} else {
|
||||||
<h3 class="t-op-nextlvl label-tag">${userLogin.lastLogin}</h3>
|
res.redirect('/login');
|
||||||
`;
|
}
|
||||||
itemsContainer.appendChild(item);
|
}
|
||||||
|
|
||||||
|
// InUsers route (renders the InUsers tab)
|
||||||
|
router.get('/', isAuthenticated, (req, res) => {
|
||||||
|
// Fetch all user data from the database
|
||||||
|
const userDataQuery = 'SELECT * FROM users';
|
||||||
|
|
||||||
|
mysqlConnection.query(userDataQuery, (error, userData) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching user data:', error);
|
||||||
|
res.status(500).send('Internal Server Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render the inusers page with user data
|
||||||
|
res.render('inusers', { userData: userData });
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.catch(error => console.error('Error fetching recent user logins:', error));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// User Data route
|
||||||
|
router.get('/userdata', isAuthenticated, (req, res) => {
|
||||||
|
// Fetch all user data from the database
|
||||||
|
const userDataQuery = 'SELECT * FROM users';
|
||||||
|
|
||||||
|
mysqlConnection.query(userDataQuery, (error, userData) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching user data:', error);
|
||||||
|
res.status(500).send('Internal Server Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render the user-data page with user data
|
||||||
|
res.render('user-data', { userData: userData });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Edit User Data route
|
||||||
|
router.get('/edituserdata', isAuthenticated, (req, res) => {
|
||||||
|
res.render('edit-user-data');
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
208
Sean/views/inusers.ejs
Normal file
208
Sean/views/inusers.ejs
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
<!-- views/inusers.ejs -->
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>In-House Users</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: 'Arial', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar {
|
||||||
|
height: 100%;
|
||||||
|
width: 250px;
|
||||||
|
position: fixed;
|
||||||
|
background-color: #333;
|
||||||
|
padding-top: 60px;
|
||||||
|
transition: 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar img {
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar a {
|
||||||
|
padding: 10px 15px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 18px;
|
||||||
|
color: white;
|
||||||
|
display: block;
|
||||||
|
transition: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar a:hover {
|
||||||
|
background-color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
margin-left: 250px;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
#sidebar {
|
||||||
|
width: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
left: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse span {
|
||||||
|
display: block;
|
||||||
|
background: white;
|
||||||
|
height: 5px;
|
||||||
|
width: 30px;
|
||||||
|
margin: 6px auto;
|
||||||
|
transition: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse:hover span:nth-child(1) {
|
||||||
|
transform: rotate(-45deg) translate(-5px, 6px);
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse:hover span:nth-child(2) {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarCollapse:hover span:nth-child(3) {
|
||||||
|
transform: rotate(45deg) translate(-5px, -6px);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add additional styles specific to inusers.ejs below */
|
||||||
|
#userDataContainer {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th, td {
|
||||||
|
border: 1px solid #dddddd;
|
||||||
|
text-align: left;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="sidebar">
|
||||||
|
<img src="LOGO.PNG" alt="Custom Image">
|
||||||
|
<div id="sidebarCollapse">
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
</div>
|
||||||
|
<a href="#" id="userDataLink">User Data</a>
|
||||||
|
<a href="/inusers/edituserdata">Edit User Data</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
<h2>Welcome to the In-House Users Page</h2>
|
||||||
|
|
||||||
|
<div id="userDataContainer">
|
||||||
|
<h3>All Users</h3>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Username</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Password</th>
|
||||||
|
<th>Last Login</th>
|
||||||
|
<th>Job Title</th>
|
||||||
|
<!-- Add more table headers as needed -->
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% if (allUsers && allUsers.length > 0) { %>
|
||||||
|
<% allUsers.forEach(user => { %>
|
||||||
|
<tr>
|
||||||
|
<td><%= user.name %></td>
|
||||||
|
<td><%= user.username %></td>
|
||||||
|
<td><%= user.email %></td>
|
||||||
|
<td><%= user.password %></td>
|
||||||
|
<td><%= new Date(user.lastLogin).toLocaleString('en-US', { timeZone: 'Asia/Singapore' }) %></td>
|
||||||
|
<td><%= user.jobTitle %></td>
|
||||||
|
<!-- Add more table data cells as needed -->
|
||||||
|
</tr>
|
||||||
|
<% }); %>
|
||||||
|
<% } else { %>
|
||||||
|
<tr>
|
||||||
|
<td colspan="6">No users available.</td>
|
||||||
|
</tr>
|
||||||
|
<% } %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Additional content for In-House Users page goes here -->
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.getElementById('sidebarCollapse').addEventListener('click', function () {
|
||||||
|
document.getElementById('sidebar').style.width = (document.getElementById('sidebar').style.width === '250px') ? '0' : '250px';
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
function displayUserData() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/inusers/userdata',
|
||||||
|
method: 'GET',
|
||||||
|
dataType: 'html',
|
||||||
|
success: function (data) {
|
||||||
|
$('#userDataContainer').html(data);
|
||||||
|
},
|
||||||
|
error: function (error) {
|
||||||
|
console.error('Error fetching user data:', error);
|
||||||
|
// Handle error as needed
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the function when the page loads
|
||||||
|
displayUserData();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -120,7 +120,7 @@
|
|||||||
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
|
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bytes": "3.1.2",
|
"bytes": "3.1.2",
|
||||||
"content-type": "~1.0.4",
|
"content-type": "~1.0.5",
|
||||||
"debug": "2.6.9",
|
"debug": "2.6.9",
|
||||||
"depd": "2.0.0",
|
"depd": "2.0.0",
|
||||||
"destroy": "1.2.0",
|
"destroy": "1.2.0",
|
||||||
@ -128,7 +128,7 @@
|
|||||||
"iconv-lite": "0.4.24",
|
"iconv-lite": "0.4.24",
|
||||||
"on-finished": "2.4.1",
|
"on-finished": "2.4.1",
|
||||||
"qs": "6.11.0",
|
"qs": "6.11.0",
|
||||||
"raw-body": "2.5.1",
|
"raw-body": "2.5.2",
|
||||||
"type-is": "~1.6.18",
|
"type-is": "~1.6.18",
|
||||||
"unpipe": "1.0.0"
|
"unpipe": "1.0.0"
|
||||||
},
|
},
|
||||||
|
@ -17,9 +17,13 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/Newtbot/MP#readme",
|
"homepage": "https://github.com/Newtbot/MP#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
"coap": "^1.3.0",
|
"coap": "^1.3.0",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
|
"ejs": "^3.1.9",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
"express-session": "^1.17.3",
|
||||||
|
"mysql": "^2.18.1",
|
||||||
"mysql2": "^3.6.5",
|
"mysql2": "^3.6.5",
|
||||||
"sequelize": "^6.35.2",
|
"sequelize": "^6.35.2",
|
||||||
"validator": "^13.11.0"
|
"validator": "^13.11.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user