Skip to content

Commit

Permalink
SIN number and logged in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Sagara authored and Henrique Sagara committed Mar 2, 2024
1 parent 110c40c commit 5b623e3
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 155 deletions.
2 changes: 1 addition & 1 deletion modules/data-service-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function isUserIdExists(userId) {

async function getUserByEmail(client, email) {
const result = await client.db(dbName).collection(userCollection).findOne({email: email})

return result
}

Expand Down
43 changes: 43 additions & 0 deletions public/jsForPages/shiftTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,49 @@ document.addEventListener("DOMContentLoaded", function () {

});

// Post the time on the data base
document.getElementById("timeInBtn").addEventListener("click", async () => {
try {
// Make an AJAX request to the server to trigger the time-in action
const response = await fetch("/time-in", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ userId: 1 }),
});

if (response.ok) {
const data = await response.json();
console.log(data.message);
} else {
console.error("Error recording time-in");
}
} catch (error) {
console.error(error);
}
});

document.getElementById("timeOutBtn").addEventListener("click", async () => {
try {
// Make an AJAX request to the server to trigger the time-in action
const response = await fetch("/time-out", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ userId: 1 }),
});

if (response.ok) {
const data = await response.json();
console.log(data.message);
} else {
console.error("Error recording time-in");
}
} catch (error) {
console.error(error);
}
});


48 changes: 44 additions & 4 deletions routes/root.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import express from "express";
import path from "path";
import bodyParser from "body-parser";
import bcrypt from 'bcrypt'
import bcrypt from 'bcrypt';
import { client, authenticateUser } from "../modules/database.js";
import { deleteUserById, addNewUser} from "../modules/data-service.js";
import { deleteUserById, addNewUser, timeIn, timeOut} from "../modules/data-service.js";
import { createUser, getUserByEmail, getUserByName, getUserBySin } from "../modules/data-service-auth.js";


Expand All @@ -13,6 +13,42 @@ const currentDir = process.cwd();

router.use(bodyParser.urlencoded({ extended: true}));

router.post("/time-in", authenticateUser, async (req, res) => {
// const userId = req.body.userId;
const userId = req.session.user.id

console.log(userId)

try {
await timeIn(client, userId);
res.status(200).json({ message: "Time-in recorded successfully" });
} catch (error) {
console.log(error);
res.status(500).json({ message: "Internal Server Error" });
}
});


router.get("/time-in", authenticateUser, (req, res) => {
res.sendFile(path.resolve(currentDir, 'views', 'time-in.html'));
});

router.post("/time-out", authenticateUser, async (req, res) => {
const userId = req.session.user.id;

try {
await timeOut(client, userId);
res.status(200).json({message: "Time-out recorded successfully"})
} catch (e) {
console.error(e);
res.status(500).json({message: "Internal Server Error"})
}
});

router.get("/time-out", authenticateUser, (req, res) => {
res.sendFile(path.resolve(currentDir, 'views', 'time-out.html'))
})

// Route to handle creating a new user
router.post("/create-user", async (req, res) => {

Expand Down Expand Up @@ -43,7 +79,7 @@ router.post("/login", async (req, res) => {
const {email, password} = req.body;

try {
const user = await getUserByEmail(email)
const user = await getUserByEmail(client, email)
console.log(user)

if(!user) {
Expand All @@ -58,12 +94,13 @@ router.post("/login", async (req, res) => {
id: user._id,
email: user.email,
}
res.status(200).json({message: 'Login successful'});
res.sendFile(path.resolve(currentDir, 'views', 'shiftTracker.html'))
}
else {
res.status(401).json({ message: 'Invalid email or password' });
}


} catch (error) {
console.error('Error during login:', error);
res.status(500).json({ message: 'Internal Server Error' });
Expand Down Expand Up @@ -104,4 +141,7 @@ router.get('/about-us', (req, res) => {
router.get('/create-user', (req, res) => {
res.sendFile(path.resolve(currentDir, 'views', 'registrationTest.html'))
})



export default router;
26 changes: 0 additions & 26 deletions routes/time-in.js

This file was deleted.

25 changes: 0 additions & 25 deletions routes/time-out.js

This file was deleted.

2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const sessionSecret = 'htsagara';
app.use(session({
secret: sessionSecret,
resave: false,
saveUninitialized: true,
saveUninitialized: false,
}))

// Call the connectToDatabase function to establish the connection
Expand Down
39 changes: 21 additions & 18 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

<link rel="stylesheet" href="/public/css/homePage.css">
<link rel="stylesheet" href="css/homePage.css">

<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
Expand Down Expand Up @@ -76,41 +76,44 @@ <h3>By CoffeeCollab</h3>
<form action="/create-user" method="POST" >

<h2 class="registerTitle">Register Now!</h2>


<!-- Full name input -->
<div class="form-floating">
<input type="text" autocomplete="off" name="fullname" class="input" id="registrationFullName" placeholder="FullName" required>


</div>

<!-- Email input -->
<div class="form-floating">
<input type="email" autocomplete="off" name="email" class="input" id="registrationEmail" placeholder="email" required>

</div>

<!-- SIN Number input -->
<div class="form-floating">
<input type="tel" autocomplete="off" name="sinNumber" class="input" id="sin" placeholder="sinNumber" required>

</div>
<input type="number" autocomplete="off" name="_id" class="input" id="sin" placeholder="sinNumber" required>
</div>

<!-- Password input -->
<div class="form-floating">
<input type="password" autocomplete="off" name="password" class="input" id="registrationPassword" placeholder="Password" required>

</div>

<!-- Password confirmation -->
<div class="form-floating">
<input type="password" autocomplete="off" name="confirmation" class="input" id="confirmPasswordRegistration" placeholder="Password" required>

</div>

<!-- Phone number input -->
<div class="form-floating">
<input type="tel" autocomplete="off" name="phone" class="input" id="tel" placeholder="phoneNumber" required>

<input type="tel" autocomplete="off" name="phone" class="input" id="tel" placeholder="phoneNumber" required>
</div>

<button id="registrationBtn" class="pushable" type="submit" onclick=" example(event) ">
<span class="shadow"></span>
<span class="edge"></span>
<span class="front">
Register
</span>
</button>

</form>
<!-- End of registration form -->
</div>
Expand Down Expand Up @@ -149,23 +152,23 @@ <h2 class="registerTitle">Register Now!</h2>
<div id="carouselExample" class="carousel slide">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="/public/pictures/toronto.webp" class="d-block w-100" alt="...">
<img src="pictures/toronto.webp" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block " id="text-context">
<h5 >Why did we decide to do a time sheet App? </h5>
<p>in back then we used to work in a restaurant where all the time sheet managed by paper sheets ,
and we would always think about how easy it'd be with an app so one day we came up with an idea of a time sheet app</p>
</div>
</div>
<div class="carousel-item">
<img src="/public/pictures/toronto2.jpg" class="d-block w-100" alt="...">
<img src="pictures/toronto2.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block " id="text-context">
<h5 >what Features did we use for this project?</h5>
<p>HTML,CSS,Bootstrap,JS,MongoDB</p>
</div>
</div>
<div class="carousel-item">

<img src="/public/pictures/toronto3.jpg" class="d-block w-100" alt="...">
<img src="pictures/toronto3.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block " id="text-context">
<h5 >Who's CoffeeCollab? </h5>
<p>Two friends who are trying to learn new things from each other and gain some experience by doing new projects. </p>
Expand All @@ -189,7 +192,7 @@ <h5 >Who's CoffeeCollab? </h5>

<div class="col " id="footer">
<div class="left-footer ">
<img src="/public/pictures/CoffeeCollab.jpeg" >
<img src="pictures/CoffeeCollab.jpeg" >
<a href="mailto:[email protected]"> <h5>Contact us</h5></a>
<p>© 2023 CoffeeCollab, Inc</p>
</div>
Expand All @@ -215,6 +218,6 @@ <h5 >Who's CoffeeCollab? </h5>


</div>
<script src="/public/jsForPages/index.js"></script>
<script src="jsForPages/index.js"></script>
</body>
</html>
10 changes: 8 additions & 2 deletions views/shiftTracker.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@
<button type="button" class="btn" id="timeInBtn">
Punch in
</button>
<button type="button" class="btn" id="break" >Take a Break</button>

<button type="button" class="btn" id="timeOutBtn" onclick="sendConfirmationMsg()">Punch out</button>
<button type="button" class="btn" id="break" >
Take a Break
</button>

<button type="button" class="btn" id="timeOutBtn" onclick="sendConfirmationMsg()">
Punch out
</button>

</div>


Expand Down
39 changes: 0 additions & 39 deletions views/time-in.html

This file was deleted.

Loading

0 comments on commit 5b623e3

Please sign in to comment.