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
e5746089
Commit
e5746089
authored
5 years ago
by
nicolas.paschoud
Browse files
Options
Downloads
Patches
Plain Diff
Adding a user at registry
parent
6324aa15
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
projet/db/hyperdrive.sql
+1
-1
1 addition, 1 deletion
projet/db/hyperdrive.sql
projet/hyperdrive-rest.js
+0
-2
0 additions, 2 deletions
projet/hyperdrive-rest.js
projet/sql-request.js
+60
-50
60 additions, 50 deletions
projet/sql-request.js
with
61 additions
and
53 deletions
projet/db/hyperdrive.sql
+
1
−
1
View file @
e5746089
...
...
@@ -39,8 +39,8 @@ CREATE TABLE IF NOT EXISTS Shares (
FOREIGN
KEY
(
file_id
)
REFERENCES
Files
(
file_id
)
);
-- Inserting datas
-- Inserting datas
INSERT
INTO
Users
VALUES
(
"a"
,
"test"
),
...
...
This diff is collapsed.
Click to expand it.
projet/hyperdrive-rest.js
+
0
−
2
View file @
e5746089
...
...
@@ -95,8 +95,6 @@ app.get('/', (req, res) => {
// resCode : [ 0: User now logged in, 1: False password, 2: Invalid username, 3: Empty user or pass ]
app
.
get
(
'
/login
'
,
(
req
,
res
)
=>
{
sql
.
connect
();
const
user
=
req
.
query
[
'
user
'
];
const
pass
=
req
.
query
[
'
pass
'
];
userObject
=
sql
.
userExist
(
user
,
pass
);
...
...
This diff is collapsed.
Click to expand it.
projet/sql-request.js
+
60
−
50
View file @
e5746089
...
...
@@ -14,21 +14,21 @@ var con = mysql.createConnection({
* @param {string} login This is the login of the user
* @param {string} pass This is the password of the user
*/
async
function
userExist
(
login
,
pass
){
function
userExist
(
login
,
pass
){
const
q
=
`SELECT login, passwd FROM Users WHERE login='
${
login
}
' AND passwd='
${
pass
}
';`
;
con
.
query
(
q
,
function
(
err
,
result
)
{
console
.
log
(
result
)
;
if
(
err
)
return
false
;
if
(
result
.
length
>
0
)
{
console
.
log
(
"
user exists
"
);
return
{
login
:
result
[
0
][
'
login
'
],
passwd
:
result
[
0
][
'
passwd
'
]
};
}
else
{
console
.
log
(
"
user don't exists
"
);
return
false
;
}
return
new
Promise
(()
=>
{
con
.
query
(
q
,
function
(
err
,
result
)
{
if
(
err
)
return
false
;
if
(
result
.
length
>
0
)
{
console
.
log
(
"
user exists
"
);
return
{
login
:
result
[
0
][
'
login
'
],
passwd
:
result
[
0
][
'
passwd
'
]
};
}
else
{
console
.
log
(
"
user don't exists
"
);
}
}
);
});
}
...
...
@@ -38,28 +38,36 @@ async function userExist(login, pass){
* @param {string} pass This is the password of the user
*/
async
function
insertUser
(
login
,
passwd
)
{
let
q
=
`INSERT INTO Users VALUES (
${
login
}
,
${
passwd
}
);`
;
re
=
await
userExist
(
login
,
passwd
);
if
(
!
re
){
console
.
log
(
"
querry
"
);
con
.
query
(
q
,
(
err
,
re
s
)
=>
{
if
(
err
)
return
false
;
console
.
log
(
"
User
"
,
login
,
"
inserted in the db
"
)
return
true
;
});
}
let
q
=
`INSERT INTO Users VALUES (
'
${
login
}
'
,
'
${
passwd
}
'
);`
;
re
turn
new
Promise
(
()
=>
{
userExist
(
login
,
passwd
).
then
(
con
.
query
(
q
,
(
err
,
res
)
=>
{
if
(
err
)
re
turn
false
;
console
.
log
(
"
User
"
,
login
,
"
inserted in the db
"
)
return
true
;
})
)
}
);
}
function
addPath
(
login
,
path
,
parent
){
let
q
=
`INSERT INTO Paths VALUES ('/
${
login
}
',
${
login
}
,
${
parent
}
);`
;
con
.
query
(
q
,
function
(
err
,
res
)
{
if
(
err
)
{
console
.
log
(
"
Error while adding a new path
"
);
console
.
log
(
err
);
return
false
;
}
console
.
log
(
"
New path
"
,
path
,
"
added succesfully !
"
);
return
true
;
/**
* This function add a new directory to a user
* @param {string} path Path to add
* @param {string} login User's path
* @param {string} parent Parent of the new folder
*/
function
addPath
(
path
,
login
,
parent
){
let
q
=
`INSERT INTO Paths VALUES ('
${
path
}
', '
${
login
}
',
${
parent
}
);`
;
return
new
Promise
(()
=>
{
con
.
query
(
q
,
function
(
err
,
res
)
{
if
(
err
)
{
console
.
log
(
"
Error while adding a new path
"
);
console
.
log
(
err
);
return
false
;
}
console
.
log
(
"
New path
"
,
path
,
"
added succesfully !
"
);
return
true
;
});
});
}
...
...
@@ -70,23 +78,11 @@ function addPath(login, path, parent){
* @param {string} pass This is the password of the user
*/
async
function
addUser
(
login
,
passwd
){
return
new
Promise
(
resolve
=>
{
a
==
true
;
return
new
Promise
(
async
()
=>
{
await
insertUser
(
login
,
passwd
).
then
(
addPath
(
'
/
'
+
login
,
login
,
null
));
});
}
// user_inserted = await insertUser(login, passwd);
// if (user_inserted) {
// path_added = await addPath(login, `/${login}`, 'NULL');
// if (path_added) {
// console.log("File added succesfully");
// return true
// }
// console.log("Error while adding a path");
// return false;
// }
// return false;
// }
/**
+----------------+-------+-----------+---------+-----------+
...
...
@@ -97,8 +93,22 @@ async function addUser(login, passwd){
| /a/coucou/test | a | /a/coucou | NULL | NULL |
+----------------+-------+-----------+---------+-----------+
*/
async
function
changePath
(
login
,
path
){
q
=
`
SELECT Paths.paths, login, parent, Files.file_id, Files.file_name
FROM Paths
LEFT JOIN Files ON Files.paths = Paths.paths
WHERE Files.file_id IS NOT NULL
AND login='
${
login
}
' AND Paths.paths='
${
path
}
'`
;
con
.
query
(
q
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
"
Error while loading the path
"
);
return
false
;
}
console
.
log
(
res
);
});
function
changePath
(
login
,
path
){
return
[
{
path
:
'
/a/coucou
'
,
...
...
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