mirror of
https://github.com/anatolykopyl/registration.git
synced 2026-03-26 04:45:25 +00:00
Status codes
This commit is contained in:
@@ -29,16 +29,16 @@ client.connect()
|
|||||||
|
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
if (req.session.loggedIn) {
|
if (req.session.loggedIn) {
|
||||||
res.sendFile(__dirname+'/public/personal.html')
|
res.status(200).sendFile(__dirname+'/public/personal.html')
|
||||||
} else {
|
} else {
|
||||||
res.sendFile(__dirname+'/public/auth.html')
|
res.status(200).sendFile(__dirname+'/public/auth.html')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/get-users', async (_, res) => {
|
app.get('/get-users', async (_, res) => {
|
||||||
try {
|
try {
|
||||||
const users = await client.db('reg_example').collection('users').find().toArray()
|
const users = await client.db('reg_example').collection('users').find().toArray()
|
||||||
res.send(users)
|
res.status(200).send(users)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Error: " + e)
|
console.log("Error: " + e)
|
||||||
res.status(500).send()
|
res.status(500).send()
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ const axios = require('axios')
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
verifyCaptcha: function (req, res, cb) {
|
verifyCaptcha: function (req, res, cb) {
|
||||||
if (!req.body['g-recaptcha-response']) {
|
if (!req.body['g-recaptcha-response']) {
|
||||||
return res.status(401).send("Invalid captcha")
|
return res.status(400).send("No captcha")
|
||||||
}
|
}
|
||||||
|
|
||||||
const URL = "https://www.google.com/recaptcha/api/siteverify?secret=" + process.env.SECRET_KEY + "&response=" + req.body['g-recaptcha-response'] + "&remoteip=" + req.socket.remoteAddress
|
const URL = "https://www.google.com/recaptcha/api/siteverify?secret=" + process.env.SECRET_KEY + "&response=" + req.body['g-recaptcha-response'] + "&remoteip=" + req.socket.remoteAddress
|
||||||
|
|
||||||
axios.get(URL).then(function (response) {
|
axios.get(URL).then(function (response) {
|
||||||
if (response.data.success !== undefined && !response.data.success) {
|
if (response.data.success !== undefined && !response.data.success) {
|
||||||
return res.status(401).send("Invalid captcha")
|
return res.status(429).send("Invalid captcha")
|
||||||
}
|
}
|
||||||
|
|
||||||
cb()
|
cb()
|
||||||
|
|||||||
Reference in New Issue
Block a user