-
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
1 parent
676ca62
commit d715b3d
Showing
5 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
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
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 |
---|---|---|
|
@@ -111,7 +111,7 @@ router.post("/reset", (req,res) => { | |
to: email, | ||
from: '[email protected]', | ||
subject: 'Reset Password', | ||
html: `<h1>You requsted for a password reset <a href="http://localhost:3000/reset/${token}">Click here</a> to reset password</h1>` | ||
html: `<h1>You requsted for a password reset <a href="http://my-magic-notes/reset/${token}.herokuapp.com">Click here</a> to reset password</h1>` | ||
}) | ||
}) | ||
.catch(err => { | ||
|
@@ -125,7 +125,6 @@ router.post("/update-password", (req,res) => { | |
const newPassword = req.body.newPassword; | ||
const confirmPassword = req.body.confirmPassword; | ||
let resetUser; | ||
console.log(token); | ||
if(newPassword == confirmPassword){ | ||
User.findOne({ | ||
resetToken: token, resetTokenExpiration: {$gt: Date.now()} | ||
|
@@ -153,7 +152,6 @@ router.post("/update-password", (req,res) => { | |
} else { | ||
res.redirect(`/reset/${token}`) | ||
req.flash('data', 'password does not match') | ||
console.log(token); | ||
} | ||
|
||
}); | ||
|
@@ -166,7 +164,6 @@ router.get('/reset/:token', (req,res) => { | |
message = null; | ||
} | ||
const token = req.params.token; | ||
console.log(token); | ||
User.findOne({ | ||
resetToken: token, resetTokenExpiration: {$gt: Date.now()} | ||
}) | ||
|
@@ -218,7 +215,7 @@ router.post("/add-user", (req, res) => { | |
to: email, | ||
from: '[email protected]', | ||
subject: 'Signup', | ||
html: `<h1>You Successfully Signed Up! <a href="http://localhost:3000/login">Click here</a> to log in</h1>` | ||
html: `<h1>You Successfully Signed Up! <a href="http://my-magic-notes/login.herokuapp.com">Click here</a> to log in</h1>` | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
|
@@ -251,7 +248,6 @@ router.post("/user-login", (req, res) => { | |
.then((doMatch) => { | ||
if (doMatch) { | ||
const user_id = user._id; | ||
console.log(user); | ||
req.session.isLoggedin = true; | ||
res.redirect(`home/${user_id}`); | ||
} else { | ||
|
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,6 +1,10 @@ | ||
const indexRouter = require('./routes/index'); | ||
const userRouter = require('./routes/user'); | ||
|
||
const fs = require('fs'); | ||
|
||
const path = require('path'); | ||
|
||
const dotenv = require('dotenv'); | ||
|
||
dotenv.config({path: './config/config.env'}); | ||
|
@@ -15,12 +19,18 @@ const session = require('express-session'); | |
|
||
const MongoDBStore = require('connect-mongodb-session')(session); | ||
|
||
const helmet = require('helmet'); | ||
|
||
const compression = require('compression'); | ||
|
||
const morgan = require('morgan'); | ||
|
||
const csrf = require('csurf'); | ||
|
||
const flash = require('connect-flash'); | ||
|
||
const store = new MongoDBStore({ | ||
uri: 'mongodb+srv://rajshahcs5:@[email protected]/magicnote?retryWrites=true&w=majority', | ||
uri: process.env.MONGO_URI, | ||
collection: 'sessions' | ||
}); | ||
|
||
|
@@ -38,13 +48,24 @@ app.use(session({secret: 'chahak', store: store, resave: true, saveUninitialized | |
|
||
const csrfProtection = csrf(); | ||
|
||
const accessLogStream = fs.createWriteStream( | ||
path.join(__dirname, 'access.log'), | ||
{ flags: 'a'} | ||
); | ||
|
||
app.use(csrfProtection); | ||
|
||
app.use((req,res,next) => { | ||
res.locals.csrfToken = req.csrfToken(); | ||
next(); | ||
}); | ||
|
||
app.use(helmet()); | ||
|
||
app.use(compression()); | ||
|
||
app.use(morgan('combined', { stream: accessLogStream})); | ||
|
||
app.use(flash()); | ||
|
||
mongoose.connect(process.env.MONGO_URI,{useNewUrlParser: true, useUnifiedTopology: true}) | ||
|