Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Voting
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dennis Willers
Voting
Commits
fb9f17d3
Commit
fb9f17d3
authored
Aug 23, 2021
by
Matthieu - Greep
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removing tokenCheck correctly
parent
c8385bb1
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
96 deletions
+56
-96
index.js
index.js
+1
-39
getPlayerVote.js
route/getPlayerVote.js
+1
-1
getVotes.js
route/getVotes.js
+1
-1
mostPlayerVoted.js
route/mostPlayerVoted.js
+1
-1
mostVotedMaps.js
route/mostVotedMaps.js
+1
-1
setVote.js
route/setVote.js
+51
-53
No files found.
index.js
View file @
fb9f17d3
...
...
@@ -26,44 +26,6 @@ connection.connect((err)=>{
}
})
/**
* Get the authorization token from the request header
* @param {import('express').Request} req
* @param {import('express').Response} res
* @param {import('mysql').Connection} sql
* @param {Function} cb the callback function to call only if the token is valid. There are no parameters.
*/
function
checkToken
(
req
,
res
,
sql
,
cb
){
var
auth
=
req
.
get
(
'
Authorization
'
)
if
(
!
auth
){
renderError
(
res
,
403
,
'
No authorization token provided
'
);
return
false
;
}
else
{
if
(
auth
.
includes
(
'
Basic
'
)){
var
token
=
auth
.
replace
(
'
Basic
'
,
''
)
sql
.
query
(
"
SELECT * FROM Auth WHERE token = ?
"
,
token
,
async
(
err
,
result
)
=>
{
if
(
err
){
console
.
error
(
err
)
renderError
(
res
,
500
,
"
Internal Server Error
"
)
}
else
{
if
(
result
.
length
<
1
){
renderError
(
res
,
401
,
"
Authorization Token not found.
"
)
}
else
{
if
(
result
[
0
].
validate
==
0
){
renderError
(
res
,
403
,
"
Authorization Token not validated.
"
)
}
else
{
console
.
log
(
'
Connexion from
'
+
result
[
0
].
description
);
cb
();
}
}
}
});
}
else
{
renderError
(
res
,
403
,
"
Token not found in Authorization header, please set a Token in Authorization header like this: 'Authorization: Basic [token]'.
"
)
}
}
}
/**
* Render a JSON response for an error
* @param {import('express').Response} res
...
...
@@ -121,7 +83,7 @@ app.get('/', (req, res) => {
})
fs
.
readdirSync
(
path
.
join
(
__dirname
,
'
route
'
)).
filter
(
file
=>
file
.
endsWith
(
'
.js
'
)).
forEach
(
function
(
file
)
{
require
(
path
.
join
(
__dirname
,
'
route
'
,
file
))(
app
,
connection
,
checkToken
,
renderError
)
require
(
path
.
join
(
__dirname
,
'
route
'
,
file
))(
app
,
connection
,
renderError
)
});
// catch 404 and forward to error handler
...
...
route/getPlayerVote.js
View file @
fb9f17d3
...
...
@@ -5,7 +5,7 @@ const path = require('path'),
* @param {import('express').Express} app
* @param {import('mysql').Connection} sql
*/
module
.
exports
=
function
(
app
,
sql
,
token
,
errorHandler
)
{
module
.
exports
=
function
(
app
,
sql
,
errorHandler
)
{
app
.
get
(
'
/
'
+
scriptName
,
function
(
req
,
res
)
{
const
mapId
=
req
.
query
.
map
||
req
.
body
.
map
,
player
=
req
.
query
.
player
||
req
.
body
.
player
;
...
...
route/getVotes.js
View file @
fb9f17d3
...
...
@@ -5,7 +5,7 @@ const path = require('path'),
* @param {import('express').Express} app
* @param {import('mysql').Connection} sql
*/
module
.
exports
=
function
(
app
,
sql
,
token
,
errorHandler
)
{
module
.
exports
=
function
(
app
,
sql
,
errorHandler
)
{
app
.
get
(
'
/
'
+
scriptName
,
function
(
req
,
res
)
{
const
mapId
=
req
.
query
.
map
||
req
.
body
.
map
;
if
(
!
mapId
)
{
...
...
route/mostPlayerVoted.js
View file @
fb9f17d3
...
...
@@ -5,7 +5,7 @@ const path = require('path'),
* @param {import('express').Express} app
* @param {import('mysql').Connection} sql
*/
module
.
exports
=
function
(
app
,
sql
,
token
,
errorHandler
)
{
module
.
exports
=
function
(
app
,
sql
,
errorHandler
)
{
app
.
get
(
'
/
'
+
scriptName
,
function
(
req
,
res
)
{
sql
.
query
(
'
SELECT player, COUNT(*) AS votes FROM votes GROUP BY player ORDER BY votes DESC
'
,
(
err
,
sqlRes
)
=>
{
if
(
err
)
{
...
...
route/mostVotedMaps.js
View file @
fb9f17d3
...
...
@@ -5,7 +5,7 @@ const path = require('path'),
* @param {import('express').Express} app
* @param {import('mysql').Connection} sql
*/
module
.
exports
=
function
(
app
,
sql
,
token
,
errorHandler
)
{
module
.
exports
=
function
(
app
,
sql
,
errorHandler
)
{
app
.
get
(
'
/
'
+
scriptName
,
function
(
req
,
res
)
{
sql
.
query
(
'
SELECT map, COUNT(*) AS votes FROM votes GROUP BY map ORDER BY votes DESC
'
,
(
err
,
sqlRes
)
=>
{
if
(
err
)
{
...
...
route/setVote.js
View file @
fb9f17d3
...
...
@@ -7,9 +7,8 @@ const path = require('path'),
* @param {import('express').Express} app
* @param {import('mysql').Connection} sql
*/
module
.
exports
=
function
(
app
,
sql
,
tokenCheck
,
errorHandler
)
{
module
.
exports
=
function
(
app
,
sql
,
errorHandler
)
{
app
.
post
(
'
/
'
+
scriptName
,
function
(
req
,
res
)
{
//tokenCheck(req, res, sql, ()=>{
const
mapId
=
req
.
query
.
map
||
req
.
body
.
map
,
player
=
req
.
query
.
player
||
req
.
body
.
player
,
vote
=
Number
(
req
.
query
.
vote
||
req
.
body
.
vote
);
...
...
@@ -62,6 +61,5 @@ module.exports = function(app, sql, tokenCheck, errorHandler) {
});
})
.
catch
((
err
)
=>
errorHandler
(
res
,
400
,
err
));
// player not found
//});
});
};
\ 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