Add verify mail API

This commit is contained in:
Moe Poi ~ 2021-11-17 15:51:52 +07:00
parent fdf319eac9
commit e1c0a2dea4

View file

@ -150,7 +150,9 @@ router.post('/login', async (req, res) => {
ip: req.body.ip || req.headers['x-forwarded-for'] || req.socket.remoteAddress, ip: req.body.ip || req.headers['x-forwarded-for'] || req.socket.remoteAddress,
session: token, session: token,
}) })
conn.query('UPDATE users SET ? WHERE email ="' + req.body.email + '"', {session: JSON.stringify(session)}, function (err, result) { conn.query('UPDATE users SET ? WHERE email ="' + req.body.email + '"', {
session: JSON.stringify(session)
}, function (err, result) {
if (err) { if (err) {
res.status(400); res.status(400);
res.json({ res.json({
@ -187,4 +189,53 @@ router.post('/login', async (req, res) => {
} }
}) })
router.get('/verify-mail', async (req, res) => {
const conn = db.connect();
conn.query(
'SELECT * FROM users WHERE token ="' + req.query.token + '"',
function (err, result) {
if (err) {
res.status(400);
res.json({
'message': 'Bad Request'
})
}
if (result.length > 0) {
if (result[0].verify == 0) {
var data = {
verify: 1,
};
db_connect.query(
'UPDATE users SET ? WHERE email ="' + result[0].email + '"',
data,
function (err, result) {
if (err) {
res.status(400);
res.json({
'message': 'Bad Request'
})
} else {
res.status(200);
res.json({
'message': 'Verified ~'
})
}
}
);
} else {
res.status(403);
res.json({
'message': 'Forbidden'
})
}
} else {
res.status(400);
res.json({
'message': 'Bad Request'
})
}
}
);
})
module.exports = router; module.exports = router;