Skip to content

Commit

Permalink
Resolved conflicts in node_modules/.package-lock.json, package-lock.j…
Browse files Browse the repository at this point in the history
…son, and views/shiftTracker.html
  • Loading branch information
EvrimCiftci committed Feb 23, 2024
2 parents ec519d1 + 7a69a7a commit 0da5425
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 51 deletions.
Binary file modified .DS_Store
Binary file not shown.
32 changes: 29 additions & 3 deletions modules/data-service-auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import { client, userCollection } from "./database.js";
import { client, userCollection, dbName } from "./database.js";
import bcrypt from 'bcrypt';

const saltRounds = 10;

async function createUser(client, newUser) {
const hashedPassword = await hashPassword(newUser.password);
newUser.password = hashedPassword;

const result = await client.db(dbName).collection(userCollection).insertOne(newUser);

console.log(`${result.insertedCount} new user(s) created with the following id(s)`);
console.log(result.insertedIds);
console.log(`${result.name} new user(s) created in users database`);

return result;
}

async function isUserIdExists(userId) {
const result = await client.db(dbName).collection(userCollection).findOne({ _id: userId });

return !!result;
}

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

async function hashPassword(password){
return await bcrypt.hash(password, saltRounds)
}

export {
createUser,
isUserIdExists,
getUserByEmail,
};
9 changes: 4 additions & 5 deletions modules/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { client, dbName, collectionName, connectToDatabase } from "./database.js
// connectToDatabase();

// Create new user
async function createUser(client, newUser) {
const result = await client.db(dbName).collection(collectionName).insertOne(newUser);
async function addNewUser(client, userId) {
const result = await client.db(dbName).collection(collectionName).insertOne({_id: userId});

console.log(`${result.insertedCount} new user(s) created with the following id(s)`);
console.log(result.insertedIds);
console.log(`${result._id} new user(s) created in hoursRecords database`);
}


Expand Down Expand Up @@ -115,7 +114,7 @@ export {
timeIn,
timeOut,
calculateWorkedHours,
createUser,
addNewUser,
queryAllRecords,
deleteUserById,
};
15 changes: 14 additions & 1 deletion modules/database.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import express from "express";
import path from "path";
import { MongoClient } from "mongodb";
import dotenv from "dotenv";
dotenv.config();
Expand All @@ -8,6 +10,15 @@ const dbName = "timesheet_app";
const collectionName = "hoursRecords";
const userCollection = "users"

const authenticateUser = (req, res, next) => {
if(req.session.user) {
next()
}
else {
res.status(401).json({message: 'Unauthorized'});
}
}

// Function to connect to the MongoDB server
async function connectToDatabase() {
try {
Expand All @@ -29,4 +40,6 @@ async function listDatabases(client) {
});
}

export { client, dbName, collectionName, userCollection, listDatabases, connectToDatabase };


export { client, dbName, collectionName, userCollection, listDatabases, connectToDatabase, authenticateUser };
60 changes: 60 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"date-fns": "^3.3.0",
"dotenv": "^16.4.1",
"express": "^4.18.2",
"express-session": "^1.18.0",
"mongodb": "^6.3.0",
"mongoose": "^8.1.0",
"react": "^18.2.0",
Expand Down
Loading

0 comments on commit 0da5425

Please sign in to comment.