From 2beffa46fba7d592d33a64e4e183ce0c98dba72f Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 26 Jun 2020 06:07:33 -0500 Subject: [PATCH] Add updateChat function in api --- src/api.ts | 6 +++++- src/http.ts | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index bd9a853..10d0327 100644 --- a/src/api.ts +++ b/src/api.ts @@ -33,6 +33,10 @@ async function update(fields: object){ await db.query('UPDATE users,user_meta SET'+qs+' WHERE users.username='+db.raw.escape(fields['name'])+' AND user_meta.username='+db.raw.escape(fields['name'])); return {"success":""}; } +async function updateChat(fields: object){ + await db.query('UPDATE chat_integration SET xmpp='+db.raw.escape(fields['xmpp'])+', discord='+db.raw.escape(fields['discord'])+', irc='+db.raw.escape(fields['irc'])+', twitch='+db.raw.escape(fields['twitch'])+' WHERE username='+db.raw.escape(fields['name'])); + return {"success":""}; +} async function changepwd(name: string, password: string, newpwd: string){ if(!name || !password || !newpwd) return {"error":"Insufficient parameters"}; @@ -56,4 +60,4 @@ async function login(name: string, password: string){ return false; } -export { register, update, changepwd, changesk, login }; \ No newline at end of file +export { register, update, changepwd, changesk, login, updateChat }; \ No newline at end of file diff --git a/src/http.ts b/src/http.ts index 0ed254b..251c252 100644 --- a/src/http.ts +++ b/src/http.ts @@ -181,6 +181,28 @@ async function initAPI() { res.send(result); });*/ }); + app.post('/api/user/update/chat', (req, res) => { + validToken(req.cookies.Authorization).then((t) => { + if(t) { + return api.updateChat({name: t['username'], + discord: "discord" in req.body ? req.body.discord : false, + xmpp: "xmpp" in req.body ? req.body.xmpp : false, + twitch: "twitch" in req.body ? req.body.twitch : false, + irc: "irc" in req.body ? req.body.irc : false, + }).then((r) => { + res.send(r); + return; + }); + } + else { + res.send('{"error":"invalid token"}'); + return; + } + }); + /*api.update(req.body.username, req.body.password, req.body.title, req.body.bio, req.body.record).then((result) => { + res.send(result); + });*/ + }); app.post('/api/user/password', (req, res) => { validToken(req.cookies.Authorization).then((t) => { if(t) {