From e1c0a2dea4ad3e80cdbde409b9d58bbf851598fa Mon Sep 17 00:00:00 2001 From: moepoi Date: Wed, 17 Nov 2021 15:51:52 +0700 Subject: [PATCH] Add verify mail API --- routes/api.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 0c52177..6d34ee6 100644 --- a/routes/api.js +++ b/routes/api.js @@ -150,7 +150,9 @@ router.post('/login', async (req, res) => { ip: req.body.ip || req.headers['x-forwarded-for'] || req.socket.remoteAddress, 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) { res.status(400); 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; \ No newline at end of file