From 259d9b8be8cac31e3c5cb4f393cf507c08bb90fe Mon Sep 17 00:00:00 2001 From: Amanda Yee Date: Sun, 6 Oct 2024 14:14:42 -0400 Subject: [PATCH 1/2] add all team members into initdb file --- code/server/initdb.js | 51 ++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/code/server/initdb.js b/code/server/initdb.js index 9cb906403..97f7c12e8 100644 --- a/code/server/initdb.js +++ b/code/server/initdb.js @@ -36,20 +36,46 @@ async function init() { let user1 = new User({ userId: 10001, - email: "test@gmail.com", - passwordHashed: "pa55w0rd", - name: "John Smith", + email: "akyee@bu.edu", + passwordHashed: "password", + name: "Amanda Yee", createdAt: "2024-09-01", - goals: [goal1, goal2] + goals: [goal1, goal2] // Connect default goals to user }) let user2 = new User({ userId: 10002, - email: "hello@bu.edu", - passwordHashed: "b0st0nuniversity", - name: "Jane Doe", - // createdAt: "2024-09-01", // testing the default param in schema works - goals: [] + email: "abbieyl@bu.edu", + passwordHashed: "password", + name: "Abbie-Yu Luo" + }) + + let user3 = new User({ + userId: 10003, + email: "ccerav@bu.edu", + passwordHashed: "password", + name: "Chris Ceravolo" + }) + + let user4 = new User({ + userId: 10004, + email: "elee27@bu.edu", + passwordHashed: "password", + name: "Eddie Lee" + }) + + let user5 = new User({ + userId: 10005, + email: "kenlight@bu.edu", + passwordHashed: "password", + name: "Kenny Light" + }) + + let user6 = new User({ + userId: 10006, + email: "zihaoq@bu.edu", + passwordHashed: "password", + name: "Zihao Qian" }) let dailyEntry1 = new DailyEntry({ @@ -64,10 +90,9 @@ async function init() { }) await Promise.all([ - user1.save(), - user2.save(), - goal1.save(), - goal2.save(), + user1.save(), user2.save(), user3.save(), + user4.save(), user5.save(), user6.save(), + goal1.save(), goal2.save(), dailyEntry1.save() ]) From a8534084c35672ff83bbb7663873008eaf970a3e Mon Sep 17 00:00:00 2001 From: Amanda Yee Date: Sun, 6 Oct 2024 14:23:15 -0400 Subject: [PATCH 2/2] hash password as default --- code/server/initdb.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/code/server/initdb.js b/code/server/initdb.js index 97f7c12e8..5661a80ee 100644 --- a/code/server/initdb.js +++ b/code/server/initdb.js @@ -1,5 +1,6 @@ // This file is for initializing data to the MongoDB database +const bcrypt = require('bcrypt'); const db = require("./config/db.js") const User = require("./models/User"); @@ -16,6 +17,11 @@ async function init() { // await Goal.deleteMany({}) // await DailyEntry.deleteMany({}) + // hashing "password" to be used as default password for users created here + const saltRounds = 10; + const hashedPassword = await bcrypt.hash("password", saltRounds); + + let goal1 = new Goal({ goalId: 50001, type: "sleep", @@ -37,7 +43,7 @@ async function init() { let user1 = new User({ userId: 10001, email: "akyee@bu.edu", - passwordHashed: "password", + passwordHashed: hashedPassword, name: "Amanda Yee", createdAt: "2024-09-01", goals: [goal1, goal2] // Connect default goals to user @@ -46,35 +52,35 @@ async function init() { let user2 = new User({ userId: 10002, email: "abbieyl@bu.edu", - passwordHashed: "password", + passwordHashed: hashedPassword, name: "Abbie-Yu Luo" }) let user3 = new User({ userId: 10003, email: "ccerav@bu.edu", - passwordHashed: "password", + passwordHashed: hashedPassword, name: "Chris Ceravolo" }) let user4 = new User({ userId: 10004, email: "elee27@bu.edu", - passwordHashed: "password", + passwordHashed: hashedPassword, name: "Eddie Lee" }) let user5 = new User({ userId: 10005, email: "kenlight@bu.edu", - passwordHashed: "password", + passwordHashed: hashedPassword, name: "Kenny Light" }) let user6 = new User({ userId: 10006, email: "zihaoq@bu.edu", - passwordHashed: "password", + passwordHashed: hashedPassword, name: "Zihao Qian" })