Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cbdiscord
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Geovanny E. Vera Pazmino
cbdiscord
Commits
c635527c
Commit
c635527c
authored
Mar 31, 2020
by
Geovera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save 1
parent
ea03ea61
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
1 deletion
+69
-1
database.js
server/database/database.js
+2
-0
main.js
server/main.js
+4
-0
units.js
server/models/units.js
+2
-0
users.js
server/models/users.js
+18
-1
package-lock.json
server/package-lock.json
+5
-0
package.json
server/package.json
+1
-0
units.js
server/routes/units.js
+2
-0
users.js
server/routes/users.js
+2
-0
auth.js
server/util/auth.js
+33
-0
No files found.
server/database/database.js
View file @
c635527c
'use strict'
;
const
fs
=
require
(
'fs'
);
const
MySQL
=
require
(
'promise-mysql'
);
...
...
server/main.js
View file @
c635527c
'use strict'
;
const
Koa
=
require
(
'koa'
);
const
bodyParser
=
require
(
'koa-body'
);
const
auth
=
require
(
'./util/auth'
);
const
unitsRouter
=
require
(
'./routes/units'
);
const
app
=
new
Koa
();
app
.
use
(
bodyParser
());
app
.
use
(
auth
());
app
.
use
(
unitsRouter
.
routes
()).
use
(
unitsRouter
.
allowedMethods
());
...
...
server/models/units.js
View file @
c635527c
'use strict'
;
const
db
=
require
(
'../database/database'
);
const
units
=
{};
...
...
server/models/users.js
View file @
c635527c
'use strict'
const
db
=
require
(
'../database/database'
);
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
;
\ No newline at end of file
server/package-lock.json
View file @
c635527c
...
...
@@ -164,6 +164,11 @@
"resolved"
:
"https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz"
,
"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"
:
{
"version"
:
"1.1.1"
,
"resolved"
:
"https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz"
,
...
...
server/package.json
View file @
c635527c
...
...
@@ -2,6 +2,7 @@
"name"
:
"cb-server"
,
"dependencies"
:
{
"@koa/router"
:
"^8.0.8"
,
"dotenv"
:
"^8.2.0"
,
"fs"
:
"0.0.1-security"
,
"koa"
:
"^2.11.0"
,
"koa-body"
:
"^4.1.1"
,
...
...
server/routes/units.js
View file @
c635527c
'use strict'
;
const
Koa
=
require
(
'koa'
);
const
Router
=
require
(
'@koa/router'
);
...
...
server/routes/users.js
View file @
c635527c
'use strict'
;
const
Koa
=
require
(
'koa'
);
const
Router
=
require
(
'@koa/router'
);
...
...
server/util/auth.js
0 → 100644
View file @
c635527c
'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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment