aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-05-18 19:40:13 -0400
committerAdam Soltys <[email protected]>2020-05-18 19:40:13 -0400
commit816078f062fe2664eb8043ea2d6a483bd9a6c914 (patch)
treec5d1ab8b4f2cc814cbadefa876e8b20cd0024eac
parent031fa5deebb4657261b5a328fcea5e79e699cbdf (diff)
downloadcoinos-server-816078f062fe2664eb8043ea2d6a483bd9a6c914.tar.gz
coinos-server-816078f062fe2664eb8043ea2d6a483bd9a6c914.zip
token refactor
-rw-r--r--routes/users.js17
1 files changed, 5 insertions, 12 deletions
diff --git a/routes/users.js b/routes/users.js
index b01ef90f..f52a40b2 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -59,6 +59,7 @@ app.get("/users/:username", async (req, res) => {
app.post("/register", async (req, res) => {
let err = (m) => res.status(500).send(m);
let user = req.body;
+ let { token } = user;
if (!user.username) return err("Username required");
let exists = await db.User.count({ where: { username: user.username } });
@@ -83,20 +84,12 @@ app.post("/register", async (req, res) => {
let ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress;
- if (!user.token) return res.status(500).send("Missing captcha token");
+ if (!token) return res.status(500).send("Missing captcha token");
let success, score;
try {
- const url = `https://www.google.com/recaptcha/api/siteverify?secret=${config.captcha}&response=${user.token}&remoteip=${ip}`;
- let captcha = await axios.post(
- url,
- {
- secret: config.captcha,
- response: user.token,
- remoteip: ip,
- },
- { timeout: 1000 }
- );
+ const url = `https://www.google.com/recaptcha/api/siteverify?secret=${config.captcha}&response=${token}&remoteip=${ip}`;
+ let captcha = await axios.post(url, { timeout: 1000 });
({ success, score } = captcha.data);
@@ -160,7 +153,7 @@ app.post("/register", async (req, res) => {
user = await getUser(user.username);
res.send(pick(user, ...whitelist));
emit(user.username, "user", user);
- l.info("new user", user.username, ip, token, score);
+ l.info("new user", user.username, ip, score);
});
app.post("/disable2fa", auth, twofa, async (req, res) => {