From aad4b5b2736deeb449b7d1e328ae3259be58a115 Mon Sep 17 00:00:00 2001 From: Expand-sys Date: Tue, 20 Jul 2021 11:00:48 +1000 Subject: [PATCH] pushing mostly finished frontend for the refractor --- index.js | 18 +++++++++------- routes/admin.js | 46 +++++++++++++++++++++-------------------- routes/settings.js | 2 +- views/adminsettings.pug | 2 +- views/layout.pug | 2 +- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/index.js b/index.js index 036a46a..cc05e61 100644 --- a/index.js +++ b/index.js @@ -283,6 +283,7 @@ fastify.post("/register", async function (req, res) { res.redirect("/register"); } else { //let checkuser = await client.addUser(name, password); + try { let checkuser = await got.post(`${api}/user/register`, { headers: { @@ -293,16 +294,16 @@ fastify.post("/register", async function (req, res) { pass: `${password}`, }, }); + if (checkuser) { + req.session.set("successes", "Account Created! please Log in"); + } } catch (e) { + console.log(e); req.session.set("errors", `${e.response.body}`); console.log(e.response.body); } - console.log(await checkuser); - if (checkuser) { - req.session.set("successes", "Account Created! please Log in"); - } - res.redirect("/login"); + res.redirect("/register"); } }); @@ -321,7 +322,6 @@ fastify.post("/login", async function (req, res) { }*/ let auth = btoa(`${name}:${password}`); auth = `Basic ${auth}`; - console.log(auth); let adminTest; try { adminTest = await got.post(`${api}/admin/verify_account`, { @@ -330,12 +330,13 @@ fastify.post("/login", async function (req, res) { Accept: "application/json", }, }); - adminTest = JSON.parse(adminTest.body); + + adminTest = JSON.parse(adminTest.statusCode); } catch (e) { console.log(e.response.body); } console.log(adminTest); - if (adminTest) { + if (adminTest == 204) { req.session.set("b64", auth); req.session.set("admin", adminTest); req.session.set("user", name); @@ -350,6 +351,7 @@ fastify.post("/login", async function (req, res) { Accept: "application/json", }, }); + verified = JSON.parse(verified.statusCode); } catch (e) { req.session.set("errors", `${e.response.body}`); console.log(e.response.body); diff --git a/routes/admin.js b/routes/admin.js index 5d7e790..158e533 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -18,7 +18,7 @@ module.exports = function (fastify, opts, done) { async function (req, res) { //const client = new CCashClient(process.env.BANKAPIURL); //let checkalive = await client.ping(); - let checkalive = await got(`${api}/help`, { + let checkalive = await got(`${api}../properties`, { headers: { Accept: "application/json", }, @@ -75,7 +75,7 @@ module.exports = function (fastify, opts, done) { pass: init_pass, }, }); - post = post.body; + post = post.statusCode; } catch (e) { req.session.set("errors", `${e.response.body}`); console.log(e.response.body); @@ -117,7 +117,7 @@ module.exports = function (fastify, opts, done) { } console.log(balance); - if (balance) { + if (balance || balance == 0) { req.session.set( "successes", "User: " + name + " has " + balance + " truckstop shitter simoleons" @@ -154,7 +154,7 @@ module.exports = function (fastify, opts, done) { amount: parseInt(amount), }, }); - patch = patch.body; + patch = patch.statusCode; } catch (e) { req.session.set("errors", `${e.response.body}`); console.log(e.response.body); @@ -257,25 +257,27 @@ module.exports = function (fastify, opts, done) { let { name, attempt } = req.body; //let deleteUser = client.adminDeleteUser(name, attempt); - try { - let deleteUser = await got.delete(`${api}/admin/delete`, { - headers: { - Authorization: req.session.get("b64"), - Accept: "application/json", - }, - json: { - name: name, - }, - }); - deleteUser = deleteUser.body; - } catch (e) { - req.session.set("errors", `${e.response.body}`); - console.log(e.response.body); - } + if (attempt != req.session.get("adminp")) + try { + let deleteUser = await got.delete(`${api}/admin/user/delete`, { + headers: { + Authorization: req.session.get("b64"), + Accept: "application/json", + }, + json: { + name: name, + }, + }); + deleteUser = deleteUser.statusCode; + console.log(deleteUser); + if (deleteUser) { + req.session.set("successes", "User Deletion Successful"); + } + } catch (e) { + req.session.set("errors", `${e.response.body}`); + console.log(e.response.body); + } - if (deleteUser) { - req.session.set("successes", "User Deletion Successful"); - } res.redirect("/admin"); } ); diff --git a/routes/settings.js b/routes/settings.js index 088f971..84d099d 100644 --- a/routes/settings.js +++ b/routes/settings.js @@ -22,7 +22,7 @@ module.exports = function (fastify, opts, done) { async function (req, res) { //const client = new CCashClient(process.env.BANKAPIURL); //let checkalive = await client.ping(); - let checkalive = await got(`${api}/help`, { + let checkalive = await got(`${api}../properties`, { headers: { Accept: "application/json", }, diff --git a/views/adminsettings.pug b/views/adminsettings.pug index e02239d..be7675a 100644 --- a/views/adminsettings.pug +++ b/views/adminsettings.pug @@ -4,7 +4,7 @@ extends layout block content .container h1 Settings, logged in as: #{user} - if admin == true + if admin == 204 br .card.shadow-lg center diff --git a/views/layout.pug b/views/layout.pug index bb716ec..60fa358 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -39,7 +39,7 @@ html a.nav-link(href='/BankF').text-white Bank li.nav-item a.nav-link(href='/settings').text-white Settings - if admin == true + if admin == 204 li.nav-item a.nav-link(href='/admin').text-white Admin .container