Created
October 26, 2018 15:30
-
-
Save laniltee/7d880638f9346fd1d4de056c6d6c0e14 to your computer and use it in GitHub Desktop.
form validation with session
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
// Submit Form Data | |
app.post('/posts', (req, res) => { | |
const inputTitle = req.body.inputTitle; | |
const inputContent = req.body.inputContent; | |
const inputToken = req.body.inputToken; | |
const sessionID = req.cookies['session-id']; | |
// Checking if Session ID matches CSRF Cookie | |
if (SESSION_IDS[sessionID] && SESSION_IDS[sessionID] === inputToken) { | |
console.log("Post Content: Valid Session Found !"); | |
res.sendFile('views/form-success.html', {root: __dirname}); | |
} else { | |
console.log("Post Content: No Valid Session Found !"); | |
res.sendFile('views/form-error.html', {root: __dirname}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment