Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2019_TP2
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
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
nicolas.paschoud
2019_TP2
Commits
925b11a8
Commit
925b11a8
authored
5 years ago
by
nicolas.paschoud
Browse files
Options
Downloads
Patches
Plain Diff
Update the login check
parent
8944a022
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
projet/hyperdrive-rest.js
+2
-0
2 additions, 0 deletions
projet/hyperdrive-rest.js
projet/sql-request.js
+60
-44
60 additions, 44 deletions
projet/sql-request.js
with
62 additions
and
44 deletions
projet/hyperdrive-rest.js
+
2
−
0
View file @
925b11a8
...
@@ -253,6 +253,8 @@ app.get('/download/:file_id', (req, res) => {
...
@@ -253,6 +253,8 @@ app.get('/download/:file_id', (req, res) => {
* param
* param
*/
*/
app
.
get
(
'
/change-path*
'
,
(
req
,
res
)
=>
{
app
.
get
(
'
/change-path*
'
,
(
req
,
res
)
=>
{
sql
.
changeDirectory
(
'
a
'
,
req
.
params
[
'
0
'
]);
res
.
send
(
`Request for a change path (
${
req
.
params
[
'
0
'
]}
)`
)
res
.
send
(
`Request for a change path (
${
req
.
params
[
'
0
'
]}
)`
)
})
})
...
...
This diff is collapsed.
Click to expand it.
projet/sql-request.js
+
60
−
44
View file @
925b11a8
...
@@ -14,22 +14,21 @@ var con = mysql.createConnection({
...
@@ -14,22 +14,21 @@ var con = mysql.createConnection({
* @param {string} login This is the login of the user
* @param {string} login This is the login of the user
* @param {string} pass This is the password of the user
* @param {string} pass This is the password of the user
*/
*/
function
userExist
(
login
,
pass
){
function
userExist
(
login
,
pass
,
callback
){
const
q
=
`SELECT login, passwd FROM Users WHERE login='
${
login
}
' AND passwd='
${
pass
}
';`
;
const
q
=
`SELECT login, passwd FROM Users WHERE login='
${
login
}
' AND passwd='
${
pass
}
';`
;
return
new
Promise
(()
=>
{
con
.
query
(
q
,
function
(
err
,
result
)
{
con
.
query
(
q
,
function
(
err
,
result
)
{
if
(
err
)
return
false
;
if
(
err
)
return
false
;
if
(
result
.
length
>
0
)
{
if
(
result
.
length
>
0
)
{
console
.
log
(
"
user exists
"
);
console
.
log
(
"
user
already
exists
"
);
return
{
return
callback
(
{
login
:
result
[
0
][
'
login
'
],
login
:
result
[
0
][
'
login
'
],
passwd
:
result
[
0
][
'
passwd
'
]
passwd
:
result
[
0
][
'
passwd
'
]
};
}
)
;
}
else
{
}
else
{
console
.
log
(
"
user don't exists
"
);
console
.
log
(
"
user don't exists
"
);
return
callback
(
false
);
}
}
});
});
});
}
}
/**
/**
...
@@ -37,16 +36,17 @@ function userExist(login, pass){
...
@@ -37,16 +36,17 @@ function userExist(login, pass){
* @param {string} login This is the login of the user
* @param {string} login This is the login of the user
* @param {string} pass This is the password of the user
* @param {string} pass This is the password of the user
*/
*/
async
function
insertUser
(
login
,
passwd
)
{
function
insertUser
(
login
,
passwd
,
callback
){
let
q
=
`INSERT INTO Users VALUES ('
${
login
}
', '
${
passwd
}
');`
;
let
q
=
`INSERT INTO Users VALUES ('
${
login
}
', '
${
passwd
}
');`
;
return
new
Promise
(
(
)
=>
{
userExist
(
login
,
passwd
,
(
userExist
)
=>
{
userExist
(
login
,
passwd
).
then
(
if
(
!
userExist
){
con
.
query
(
q
,
(
err
,
res
)
=>
{
con
.
query
(
q
,
(
err
,
res
)
=>
{
if
(
err
)
return
false
;
if
(
err
)
return
callback
(
false
);
console
.
log
(
"
User
"
,
login
,
"
inserted in the db
"
)
if
(
!
res
)
{
console
.
log
(
res
);
return
callback
(
false
);}
return
true
;
console
.
log
(
"
User
"
,
login
,
"
inserted in the db
"
);
})
return
callback
(
true
);
)
});
}
});
});
}
}
...
@@ -56,18 +56,16 @@ async function insertUser(login, passwd) {
...
@@ -56,18 +56,16 @@ async function insertUser(login, passwd) {
* @param {string} login User's path
* @param {string} login User's path
* @param {string} parent Parent of the new folder
* @param {string} parent Parent of the new folder
*/
*/
function
addPath
(
path
,
login
,
parent
){
function
addPath
(
path
,
login
,
parent
,
callback
){
let
q
=
`INSERT INTO Paths VALUES ('
${
path
}
', '
${
login
}
',
${
parent
}
);`
;
let
q
=
`INSERT INTO Paths VALUES ('
${
path
}
', '
${
login
}
',
${
parent
}
);`
;
return
new
Promise
(()
=>
{
con
.
query
(
q
,
function
(
err
,
res
)
{
con
.
query
(
q
,
function
(
err
,
res
)
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
"
Error while adding a new path
"
);
console
.
log
(
"
Error while adding a new path
"
);
console
.
log
(
err
);
console
.
log
(
err
);
return
false
;
return
callback
(
false
)
;
}
}
console
.
log
(
"
New path
"
,
path
,
"
added succesfully !
"
);
console
.
log
(
"
New path
"
,
path
,
"
added succesfully !
"
);
return
true
;
return
callback
(
true
);
});
});
});
}
}
...
@@ -77,13 +75,18 @@ function addPath(path, login, parent){
...
@@ -77,13 +75,18 @@ function addPath(path, login, parent){
* @param {string} login This is the login of the user
* @param {string} login This is the login of the user
* @param {string} pass This is the password of the user
* @param {string} pass This is the password of the user
*/
*/
async
function
addUser
(
login
,
passwd
){
function
addUser
(
login
,
passwd
)
{
return
new
Promise
(
async
()
=>
{
await
insertUser
(
login
,
passwd
).
then
(
insertUser
(
login
,
passwd
,
(
insertOk
)
=>
{
addPath
(
'
/
'
+
login
,
login
,
null
));
console
.
log
(
insertOk
);
if
(
insertOk
)
{
addPath
(
'
/
'
+
login
,
login
,
null
,
(
res
)
=>
{});
console
.
log
(
"
Add ok
"
);
}
});
});
}
}
/**
/**
+----------------+-------+-----------+---------+-----------+
+----------------+-------+-----------+---------+-----------+
| paths | login | parent | file_id | file_name |
| paths | login | parent | file_id | file_name |
...
@@ -93,20 +96,33 @@ async function addUser(login, passwd){
...
@@ -93,20 +96,33 @@ async function addUser(login, passwd){
| /a/coucou/test | a | /a/coucou | NULL | NULL |
| /a/coucou/test | a | /a/coucou | NULL | NULL |
+----------------+-------+-----------+---------+-----------+
+----------------+-------+-----------+---------+-----------+
*/
*/
async
function
change
Path
(
login
,
path
){
async
function
change
Directory
(
login
,
path
,
callback
){
q
=
`
q
=
`
SELECT Paths.paths, login, parent, Files.file_id, Files.file_name
SELECT Paths.paths, login, parent, Files.file_id, Files.file_name
FROM Paths
FROM Paths
LEFT JOIN Files ON Files.paths = Paths.paths
LEFT JOIN Files ON Files.paths = Paths.paths
WHERE Files.file_id IS NOT NULL
WHERE Paths.login='
${
login
}
'
AND login='
${
login
}
' AND Paths.paths='
${
path
}
'`
;
AND Paths.paths='
${
path
}
'
OR Paths.parent='
${
path
}
';`
;
con
.
query
(
q
,
(
err
,
res
)
=>
{
con
.
query
(
q
,
(
err
,
res
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
"
Error while loading the path
"
);
console
.
log
(
"
Error while loading the path
"
);
return
false
;
return
callback
(
false
,
err
);
}
let
content
=
[];
for
(
let
i
in
res
){
content
.
push
({
paths
:
res
[
i
].
paths
,
login
:
res
[
i
].
login
,
parent
:
res
[
i
].
parent
,
file_id
:
res
[
i
].
file_id
,
file_name
:
res
[
i
].
file_name
});
}
}
console
.
log
(
res
);
console
.
log
(
content
);
});
});
return
[
return
[
...
@@ -134,6 +150,6 @@ async function changePath(login, path){
...
@@ -134,6 +150,6 @@ async function changePath(login, path){
];
];
}
}
exports
.
userExist
=
userExist
;
exports
.
addUser
=
addUser
;
exports
.
addUser
=
addUser
;
exports
.
addPath
=
addPath
;
exports
.
addPath
=
addPath
;
exports
.
changeDirectory
=
changeDirectory
;
\ No newline at end of file
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