-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved conflicts in node_modules/.package-lock.json, package-lock.j…
…son, and views/shiftTracker.html
- Loading branch information
Showing
14 changed files
with
244 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.