-
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.
- Loading branch information
0 parents
commit 880f389
Showing
104 changed files
with
50,533 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
node_modules/ | ||
/node_modules/ | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/frontend/build | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node backend/server.js |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# PeepsDB | ||
|
||
The people database (PeepsDB) integrates data from multple sources to help remotely distributed freelancer teams collaborate on software projects using cloud based technology. | ||
|
||
- This project is being tracked with Work Items in the Azure DevOps Project - https://dev.azure.com/sjultra/VzxyTools/_git/PeepsDB | ||
|
||
| Backend | Framework | Database | | ||
| ------- | --------- | -------- | | ||
| NodeJS | Express | MongoDB | | ||
|
||
# Requirements | ||
|
||
1. NodeJS >= 10.0 | ||
1. Express | ||
1. MongoDB (we are using an online instance) | ||
|
||
# Getting Started | ||
|
||
In the project directory, run: | ||
|
||
`npm install` | ||
|
||
Create a file called .env in PeepsDB folder and add the following variables in order to test it locally: | ||
|
||
1. GOOGLE_CLIENT_ID | ||
2. GOOGLE_CLIENT_SECRET | ||
3. GITHUB_CLIENT_ID | ||
4. GITHUB_CLIENT_SECRET | ||
5. MICROSOFT_CLIENT_ID | ||
6. MICROSOFT_CLIENT_SECRET | ||
7. FRONTEND_URL | ||
8. BACKEND_URL | ||
9. MONGO_URI | ||
10. JWT_SECRET | ||
11. AZURE_TENANT_ID | ||
12. AZURE_CLIENT_ID | ||
13. AZURE_CLIENT_SECRET | ||
14. ENVIRONMENT (DEV or PROD) | ||
|
||
## Start Application | ||
|
||
In the project directory, run: | ||
|
||
`npm run server` | ||
|
||
Backend runs on [http://localhost:5000](http://localhost:5000) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const mongoose = require('mongoose'); | ||
const dotenv = require('dotenv'); | ||
// const helpers = require('../utils/helpers'); | ||
// const constants = require('../utils/constants'); | ||
|
||
// config.js | ||
dotenv.config(); | ||
|
||
const connectDB = async () => { | ||
try { | ||
await mongoose.connect( | ||
process.env.MONGO_URI, | ||
{ | ||
useNewUrlParser: true, | ||
useCreateIndex: true, | ||
useFindAndModify: false, | ||
useUnifiedTopology: true, | ||
} | ||
); | ||
|
||
console.log('MongoDB Connected...'); | ||
} catch (err) { | ||
console.error(err.message); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
module.exports = connectDB; |
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
'use strict'; | ||
const jwt = require('jsonwebtoken'); | ||
const User = require('../models/User'); | ||
// const helpers = require('../utils/helpers'); | ||
// const constants = require('../utils/constants'); | ||
|
||
// Get logged in user | ||
const getLoggedInUser = async (req, res) => { | ||
try { | ||
const user = await User.findById(req.user.id).select('-password'); | ||
res.json(user); | ||
} catch (err) { | ||
console.error(err.message); | ||
res.status(500).send('Server Error'); | ||
} | ||
}; | ||
|
||
// Google callback | ||
const googleAuthCallback = (req, res) => { | ||
try { | ||
// Return the jsonwebtoken | ||
const payload = { | ||
user: { | ||
id: req.user.id, | ||
}, | ||
}; | ||
|
||
jwt.sign( | ||
payload, | ||
process.env.JWT_SECRET, | ||
{ expiresIn: 36000 }, | ||
(err, token) => { | ||
if (err) throw err; | ||
res.cookie('x-auth-cookie', token); | ||
res.redirect(process.env.FRONTEND_URL); | ||
} | ||
); | ||
} catch (err) { | ||
console.error(err.message); | ||
res.status(500).send('Server error'); | ||
} | ||
}; | ||
|
||
// Github callback | ||
const githubAuthCallback = (req, res) => { | ||
try { | ||
// Return the jsonwebtoken | ||
const payload = { | ||
user: { | ||
id: req.user.id, | ||
}, | ||
}; | ||
|
||
jwt.sign( | ||
payload, | ||
process.env.JWT_SECRET, | ||
{ expiresIn: 36000 }, | ||
(err, token) => { | ||
if (err) throw err; | ||
res.cookie('x-auth-cookie', token); | ||
res.redirect(process.env.FRONTEND_URL); | ||
} | ||
); | ||
} catch (err) { | ||
console.error(err.message); | ||
res.status(500).send('Server error'); | ||
} | ||
}; | ||
|
||
// Microsoft callback | ||
const microsoftAuthCallback = (req, res) => { | ||
try { | ||
// Return the jsonwebtoken | ||
const payload = { | ||
user: { | ||
id: req.user.id, | ||
}, | ||
}; | ||
|
||
jwt.sign( | ||
payload, | ||
process.env.JWT_SECRET, | ||
{ expiresIn: 36000 }, | ||
(err, token) => { | ||
if (err) throw err; | ||
res.cookie('x-auth-cookie', token); | ||
res.redirect(process.env.FRONTEND_URL); | ||
} | ||
); | ||
} catch (err) { | ||
console.error(err.message); | ||
res.status(500).send('Server error'); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getLoggedInUser, | ||
googleAuthCallback, | ||
githubAuthCallback, | ||
microsoftAuthCallback, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const { validationResult } = require('express-validator'); | ||
|
||
const User = require('../models/User'); | ||
const Profile = require('../models/Profile'); | ||
const Onboard = require('../models/Onboard'); | ||
|
||
// @route GET /onboard/user | ||
// @desc Get user Onboarding status | ||
// @access Private/Admin | ||
const getUserOnboardStatus = async (req, res) => { | ||
try { | ||
const userOnboardStatus = await Onboard.findOne({ | ||
user: req.params.user, | ||
}); | ||
|
||
if (!userOnboardStatus) { | ||
return res.status(400).json({ | ||
msg: 'No status for this user', | ||
}); | ||
} | ||
|
||
res.json(userOnboardStatus); | ||
} catch (err) { | ||
console.error(err.message); | ||
res.status(500).send('Server Error'); | ||
} | ||
}; | ||
|
||
// @route PUT /onboard | ||
// @desc Update user Onboarding status | ||
// @access Private/Admin | ||
const updateOnboardStatus = async (req, res) => { | ||
try { | ||
// If errors, return errors | ||
const errors = validationResult(req); | ||
if (!errors.isEmpty()) { | ||
return res.status(400).json({ | ||
errors: errors.array(), | ||
}); | ||
} | ||
|
||
// If no errors | ||
const { | ||
user, | ||
role, | ||
mutualNdaSent, | ||
mutualNdaSigned, | ||
emailSetup, | ||
sendReceiveEmail, | ||
msTeamsSetup, | ||
} = req.body; | ||
|
||
// Build onboard status object | ||
const onboardStatusFields = {}; | ||
onboardStatusFields.user = user; | ||
if (role) { | ||
onboardStatusFields.role = role; | ||
} | ||
if (mutualNdaSent) onboardStatusFields.mutualNdaSent = mutualNdaSent; | ||
if (mutualNdaSigned) onboardStatusFields.mutualNdaSigned = mutualNdaSigned; | ||
if (emailSetup) onboardStatusFields.emailSetup = emailSetup; | ||
if (sendReceiveEmail) | ||
onboardStatusFields.sendReceiveEmail = sendReceiveEmail; | ||
if (msTeamsSetup) onboardStatusFields.msTeamsSetup = msTeamsSetup; | ||
|
||
// Update role for user, profile and onboard collection | ||
const updatedRole = { | ||
role, | ||
}; | ||
|
||
let userToUpdate = await User.findOne({ | ||
_id: user, | ||
}); | ||
|
||
let profileToUpdate = await Profile.findOne({ | ||
user, | ||
}); | ||
|
||
let onboardStatusToUpdate = await Onboard.findOne({ | ||
user, | ||
}); | ||
|
||
if (!userToUpdate && !profileToUpdate && !onboardStatusToUpdate) { | ||
return res.status(400).json({ | ||
msg: 'User not found', | ||
}); | ||
} | ||
|
||
userToUpdate = await User.findByIdAndUpdate( | ||
{ _id: user }, | ||
{ $set: updatedRole }, | ||
{ new: true } | ||
); | ||
|
||
profileToUpdate = await Profile.findOneAndUpdate( | ||
{ user: user }, | ||
{ $set: updatedRole }, | ||
{ new: true } | ||
); | ||
|
||
onboardStatusToUpdate = await Onboard.findOneAndUpdate( | ||
{ user: user }, | ||
{ $set: onboardStatusFields }, | ||
{ new: true } | ||
); | ||
|
||
res.json(onboardStatusToUpdate); | ||
} catch (error) { | ||
console.error(err.message); | ||
res.status(500).send('Server Error'); | ||
} | ||
}; | ||
|
||
module.exports = { getUserOnboardStatus, updateOnboardStatus }; |
Oops, something went wrong.