Commit c635527c authored by Geovera's avatar Geovera

Save 1

parent ea03ea61
'use strict';
const fs = require('fs'); const fs = require('fs');
const MySQL = require('promise-mysql'); const MySQL = require('promise-mysql');
......
'use strict';
const Koa = require('koa'); const Koa = require('koa');
const bodyParser = require('koa-body'); const bodyParser = require('koa-body');
const auth = require('./util/auth');
const unitsRouter = require('./routes/units'); const unitsRouter = require('./routes/units');
const app = new Koa(); const app = new Koa();
app.use(bodyParser()); app.use(bodyParser());
app.use(auth());
app.use(unitsRouter.routes()).use(unitsRouter.allowedMethods()); app.use(unitsRouter.routes()).use(unitsRouter.allowedMethods());
......
'use strict';
const db = require('../database/database'); const db = require('../database/database');
const units = {}; const units = {};
......
'use strict'
const db = require('../database/database'); const db = require('../database/database');
const users = {}; const users = {};
users.getUser = async (context, next) => { user.getUserFromId = async (idText, id) => {
let sql_text = `SELECT TOP 1 id, discord_id, house_id, leadership FROM users WHERE ${idText} = ?`;
try{
let data = db.con.query(sql_text,[id]);
return data;
}catch(error){
return undefined;
}
}
users.getUser = async (context, next) => {
let user = getUserFromId(context.params.id);
if(user){
context.response.body = {user: user};
}else{
context.throw(400, 'INVALID_ID')
}
}; };
module.exports = users; module.exports = users;
\ No newline at end of file
...@@ -164,6 +164,11 @@ ...@@ -164,6 +164,11 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
}, },
"dotenv": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
},
"ee-first": { "ee-first": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"name": "cb-server", "name": "cb-server",
"dependencies": { "dependencies": {
"@koa/router": "^8.0.8", "@koa/router": "^8.0.8",
"dotenv": "^8.2.0",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"koa": "^2.11.0", "koa": "^2.11.0",
"koa-body": "^4.1.1", "koa-body": "^4.1.1",
......
'use strict';
const Koa = require('koa'); const Koa = require('koa');
const Router = require('@koa/router'); const Router = require('@koa/router');
......
'use strict';
const Koa = require('koa'); const Koa = require('koa');
const Router = require('@koa/router'); const Router = require('@koa/router');
......
'use strict';
const db = require('../database/database');
async function discordAuth(context, id){
let sql_text = `SELECT TOP 1 * FROM users WHERE discordId='${id}'`;
try{
let data = await db.con.query(sql_text);
console.log(data);
}catch(error){
console.log(error);
context.throw(400, 'INVALID DISCORD ID')
}
}
function sessionAuth(context, id) {
console.log('NOT HERE');
}
module.exports = function(opts){
return async function basicAuth(context, next){
const discordId = context.cookies.get('discordId');
const sessionId = context.cookies.get('sessionId');
if(discordId!==undefined){
discordAuth(context, discordId);
}else if(sessionId!==undefined){
sessionAuth(context, context.cookies.get('sessionId'));
}else{
context.throw(400, 'NO ID FOUND');
}
await next();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment