Add updateChat function in api

merge-requests/8/head
knotteye 2020-06-26 06:07:33 -05:00
parent 190e61557e
commit 2beffa46fb
2 changed files with 27 additions and 1 deletions

View File

@ -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 };
export { register, update, changepwd, changesk, login, updateChat };

View File

@ -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) {