-
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.
Merge pull request #2 from Deepak-Sangle/web-client
Web client
- Loading branch information
Showing
30 changed files
with
33,077 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,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
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,40 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
.DS_Store | ||
|
||
.env |
File renamed without changes.
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,40 @@ | ||
require("dotenv").config(); | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const app = express(); | ||
const mongoose = require('mongoose'); | ||
const cookieParser = require('cookie-parser'); | ||
const PORT = process.env.PORT || 5000; | ||
|
||
const corsOptions = { | ||
origin: ['http://localhost:3000', 'https://dear-diary-api.onrender.com'], | ||
credentials: true, | ||
methods: ['GET', 'POST'] | ||
}; | ||
|
||
app.use(cors(corsOptions)); | ||
app.use(cookieParser()); | ||
|
||
//Set up MongoDB Database | ||
mongoose.connect(process.env.MONGOURI); | ||
|
||
mongoose.connection.on('connected',()=>{ | ||
console.log("Database connection On"); | ||
}); | ||
mongoose.connection.on('error',(err)=>{ | ||
console.log("Error Connecting: ", err); | ||
}); | ||
|
||
//Middleware Functions | ||
app.use(express.static('public')); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: false })); | ||
|
||
//Route Requests | ||
app.use(require('./routes/auth')); | ||
app.use(require('./routes/event')); | ||
|
||
//Listen Port | ||
app.listen(PORT, (req,res)=>{ | ||
console.log(`Listening to the port ${PORT}`); | ||
}); |
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,38 @@ | ||
const crypto = require('crypto'); | ||
|
||
const NUM_BYTES = 32; | ||
const algorithm = "aes-256-cbc"; | ||
|
||
function encryptData(message, initVector, key) { | ||
const cipher = crypto.createCipheriv(algorithm, key, initVector); | ||
let encryptedData = cipher.update(message, "utf-8", "hex"); | ||
encryptedData += cipher.final("hex"); | ||
return encryptedData; | ||
} | ||
|
||
function decryptData(encryptedData, initVector, key){ | ||
const decipher = crypto.createDecipheriv(algorithm, key, initVector); | ||
let decryptedData = decipher.update(encryptedData, "hex", "utf-8"); | ||
decryptedData += decipher.final("utf-8"); | ||
return decryptedData; | ||
} | ||
|
||
function getMasterInitVector(){ | ||
const ivHex = process.env.MASTER_INIT_VECTOR; | ||
const initVector = Buffer.from(ivHex, 'hex'); | ||
return initVector; | ||
} | ||
|
||
function getMasterSecretKey(){ | ||
const secretHex = process.env.MASTER_SECRET_KEY; | ||
const secretKey = Buffer.from(secretHex, 'hex'); | ||
return secretKey; | ||
} | ||
|
||
module.exports = { | ||
encryptData, | ||
decryptData, | ||
getMasterSecretKey, | ||
getMasterInitVector, | ||
NUM_BYTES | ||
} |
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,21 @@ | ||
const User = require('../models/user'); | ||
const jwt = require("jsonwebtoken"); | ||
|
||
async function isTokenValid(req, res, next){ | ||
try { | ||
const token = req.cookies.token; | ||
if (!token) return res.status(401).send({message : "Cookies not present for authorization", success : false}); | ||
const verified = jwt.verify(token, process.env.JWT_SECRET); | ||
if (!verified) return res.status(401).send({message : "Invalid JWT Token for authorization", success : false}); | ||
const user = await User.findById({_id : verified.id}); | ||
if (!user) return res.status(401).send({message : "User with given JWT Payload does not exists", success : false}); | ||
req.id = verified.id; | ||
return next(); | ||
} catch (err) { | ||
return res.status(500).json({error: err.message, success : false }); | ||
} | ||
} | ||
|
||
module.exports = { | ||
isTokenValid | ||
} |
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,23 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const eventSchema = new mongoose.Schema({ | ||
createdBy : { | ||
type : mongoose.Schema.Types.ObjectId, | ||
required : true | ||
}, | ||
createdAt : { | ||
type : Date, | ||
required : true | ||
}, | ||
detail : { | ||
type : String | ||
}, | ||
initVector : { | ||
type : String, | ||
required : true | ||
} | ||
}); | ||
|
||
const Event = mongoose.model("Event", eventSchema); | ||
|
||
module.exports = Event; |
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 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const userSchema = new mongoose.Schema({ | ||
name : { | ||
type: String, | ||
required : true | ||
}, | ||
password : { | ||
type : String, | ||
required : true | ||
}, | ||
lastEntry : { | ||
type : Date, | ||
}, | ||
DP : { | ||
type : String, | ||
}, | ||
secretKey : { | ||
type : String, | ||
required : true | ||
} | ||
}); | ||
|
||
const User = mongoose.model("User", userSchema); | ||
|
||
module.exports = User; |
Oops, something went wrong.