Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-155
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-155
2021-155
Commits
a12e8dc4
Commit
a12e8dc4
authored
Aug 22, 2021
by
Kamal Thennakoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validate git users
parent
83c0705f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
github-scorer-cloud/api/user-validity.js
github-scorer-cloud/api/user-validity.js
+47
-0
No files found.
github-scorer-cloud/api/user-validity.js
0 → 100644
View file @
a12e8dc4
const
{
checkUserValidity
}
=
require
(
"
../services/fetchers/stats-fetcher
"
);
const
blacklist
=
require
(
"
../services/common/blacklist
"
);
const
{
clampValue
,
CONSTANTS
}
=
require
(
"
../services/common/utils
"
);
require
(
"
dotenv
"
).
config
();
const
allowCors
=
fn
=>
async
(
req
,
res
)
=>
{
res
.
setHeader
(
'
Access-Control-Allow-Credentials
'
,
true
)
res
.
setHeader
(
'
Access-Control-Allow-Origin
'
,
'
*
'
)
// another common pattern
// res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res
.
setHeader
(
'
Access-Control-Allow-Methods
'
,
'
GET,OPTIONS,PATCH,DELETE,POST,PUT
'
)
res
.
setHeader
(
'
Access-Control-Allow-Headers
'
,
'
X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version
'
)
if
(
req
.
method
===
'
OPTIONS
'
)
{
res
.
status
(
200
).
end
()
return
}
return
await
fn
(
req
,
res
)
}
// check git user exists
const
checkUserExists
=
async
(
req
,
res
)
=>
{
const
{
username
,
cache_seconds
}
=
req
.
query
;
console
.
log
(
'
check user validity...
'
);
if
(
blacklist
.
includes
(
username
))
{
return
res
.
send
(
renderError
(
"
User has been blacklisted
"
));
}
try
{
user
=
await
checkUserValidity
(
username
);
const
cacheSeconds
=
clampValue
(
parseInt
(
cache_seconds
||
CONSTANTS
.
TWO_HOURS
,
10
),
CONSTANTS
.
TWO_HOURS
,
CONSTANTS
.
ONE_DAY
,
);
res
.
setHeader
(
"
Cache-Control
"
,
`public, max-age=
${
cacheSeconds
}
`
);
return
res
.
status
(
200
).
json
({
user
:
user
});
}
catch
(
err
){
console
.
log
(
'
Error:
'
,
err
);
return
res
.
status
(
301
).
json
(
err
);
}
};
module
.
exports
=
allowCors
(
checkUserExists
)
\ 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