Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gdd-sigma-poc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume WANG
gdd-sigma-poc
Commits
515c6202
Commit
515c6202
authored
6 years ago
by
Wilson JALLET
Browse files
Options
Downloads
Patches
Plain Diff
I tried
parent
82a2a7b8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/routing/admin_router.js
+4
-3
4 additions, 3 deletions
src/routing/admin_router.js
src/server.js
+26
-1
26 additions, 1 deletion
src/server.js
with
30 additions
and
4 deletions
src/routing/admin_router.js
+
4
−
3
View file @
515c6202
...
@@ -108,18 +108,19 @@ router.post('/login', (req, res, next) => {
...
@@ -108,18 +108,19 @@ router.post('/login', (req, res, next) => {
else
if
(
!
user
)
{
else
if
(
!
user
)
{
return
res
.
json
(
403
,
{
message
:
"
Not authenticated.
"
});
return
res
.
json
(
403
,
{
message
:
"
Not authenticated.
"
});
}
}
console
.
log
(
req
.
headers
);
// return 'Origin' header, useful later
req
.
login
(
user
,
(
err
)
=>
{
req
.
login
(
user
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
return
err
;
return
err
;
}
}
// if request asks for a json, reply with a token
// if request asks for a json, reply with a token
// else redirect to admin panel
// else redirect to admin panel
(
req
.
header
(
'
accept
'
)
==
'
application/json
'
)
(
req
.
header
(
'
accept
'
)
==
'
application/json
'
)
?
res
.
json
({
message
:
'
Authentication succeeded.
'
})
?
res
.
json
({
message
:
'
Authentication succeeded.
'
})
:
res
.
redirect
(
'
/admin
'
);
:
res
.
redirect
(
'
/admin
'
);
});
});
...
...
This diff is collapsed.
Click to expand it.
src/server.js
+
26
−
1
View file @
515c6202
...
@@ -75,12 +75,36 @@ const corsOptions = {
...
@@ -75,12 +75,36 @@ const corsOptions = {
};
};
server
.
use
(
cors
(
corsOptions
));
server
.
use
(
cors
(
corsOptions
));
import
jwt
from
'
jsonwebtoken
'
;
const
SECRET_KEY
=
"
azojgc;aegpfrihzcksdlmpqsqkx
"
;
/*
const addUser = async (req, res, next) => {
const token = req.cookies.csrftoken;
if (!token) return next();
console.log(`Token is ${token}`);
try {
const { user } = jwt.verify(token, SECRET_KEY);
req.user = user;
} catch (err) {
console.log('Cookie error',err);
}
};
server.use(addUser);
*/
server
.
use
(
'
/graphql
'
,
server
.
use
(
'
/graphql
'
,
bodyParser
.
json
(),
// parse incoming HTTP request (req) as a JSON
bodyParser
.
json
(),
// parse incoming HTTP request (req) as a JSON
graphqlHTTP
(
async
(
req
,
res
,
params
)
=>
{
graphqlHTTP
(
async
(
req
,
res
,
params
)
=>
{
// vary the options *on a per-request basis*
// vary the options *on a per-request basis*
let
uid
;
let
uid
;
let
password
;
let
password
;
console
.
log
(
`User
${
req
.
user
?
req
.
user
.
uid
:
"
none
"
}
`
);
console
.
log
(
"
User authenticated:
"
,
req
.
isAuthenticated
());
if
(
req
.
isAuthenticated
())
{
if
(
req
.
isAuthenticated
())
{
try
{
try
{
...
@@ -95,7 +119,8 @@ server.use('/graphql',
...
@@ -95,7 +119,8 @@ server.use('/graphql',
uid
=
defaultUser
.
dn
.
split
(
"
=
"
)[
1
].
split
(
"
,
"
)[
0
];
uid
=
defaultUser
.
dn
.
split
(
"
=
"
)[
1
].
split
(
"
,
"
)[
0
];
password
=
defaultUser
.
passwd
;
password
=
defaultUser
.
passwd
;
}
}
// console.log("Accessing GraphQL as: ",uid);
console
.
log
(
"
Cookies:
"
,
req
.
cookies
);
return
{
return
{
schema
,
schema
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment