Skip to content
Snippets Groups Projects
Commit f371d40e authored by noe.fleury's avatar noe.fleury :computer:
Browse files
parents 5a62c5f3 2c28f085
No related branches found
No related tags found
No related merge requests found
...@@ -39,8 +39,8 @@ CREATE TABLE IF NOT EXISTS Shares ( ...@@ -39,8 +39,8 @@ CREATE TABLE IF NOT EXISTS Shares (
FOREIGN KEY (file_id) REFERENCES Files(file_id) FOREIGN KEY (file_id) REFERENCES Files(file_id)
); );
-- Inserting datas
-- Inserting datas
INSERT INTO Users INSERT INTO Users
VALUES VALUES
("a", "test"), ("a", "test"),
......
function new_file(file_name, file_id) { function new_file(file_name, file_id) {
content = ` content = `
<div class="file" id="${file_id}"> <div class="file" id="${file_id}">
<p> <p>
<button> <button>
...@@ -9,17 +9,19 @@ function new_file(file_name, file_id) { ...@@ -9,17 +9,19 @@ function new_file(file_name, file_id) {
</p> </p>
</div> </div>
` `
document.getElementById("drive").append(content); document.getElementById("content-drive").innerHTML += content;
} }
function new_folder (folder_name) { function new_folder (folder_name, path) {
content = ` content = `
<div class="folder"> <div class="folder">
<p> <p>
<button><img src="/images/folder_img.png" height="50px"></button> <button onclick="change_path('${path}')">
<img src="/images/folder_img.png" height="50px">
</button>
<p>${folder_name}</p> <p>${folder_name}</p>
</p> </p>
</div> </div>
`; `;
document.getElementById("drive").append(content); document.getElementById("content-drive").innerHTML += content;
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<link rel="stylesheet" type="text/css" href="/styles/style.css"> <link rel="stylesheet" type="text/css" href="/styles/style.css">
<script src="jquery-3.4.1.min.js"></script> <script src="jquery-3.4.1.min.js"></script>
<script src="element-style.js"></script> <script src="element-style.js"></script>
<script src="show-content.js"></script>
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title> <title>Document</title>
</head> </head>
...@@ -14,13 +15,16 @@ ...@@ -14,13 +15,16 @@
<div id="hyperdrive"> <div id="hyperdrive">
<div id="menu"> <div id="menu">
<h3>Menu</h3> <h3>Menu</h3>
<button><img src="/images/file_img.png" height="50px"></button> <input type="text" id="username">
<input type="password" id="passwd">
<button onclick="login()">Login</button>
</div> </div>
<div id="drive"> <div id="drive">
<h3>Drive</h3> <h3>Drive</h3>
<script type="javascript"> <p id="dir_name"></p>
<div id="content-drive">
</script>
</div>
</div> </div>
<div id="info"> <div id="info">
<h3>Infos</h3> <h3>Infos</h3>
......
"use strict";
function change_path(path){
document.getElementById("content-drive").innerHTML = "";
$.ajax({url: 'change-path'+path, success: function(result){
console.log(result);
document.getElementById("dir_name").innerHTML = "Directory : " + path;
for (let i in result){
if (result[i].file_id){
new_file(result[i].file_name, result[i].file_id);
} else {
if (path !== result[i].paths){
let name = result[i].paths.split("/");
new_folder(name[name.length-1], result[i].paths);
}
}
}
}});
}
function login() {
let username = document.getElementById("username").value
let passwd = document.getElementById("passwd").value
console.log("login",
username,
passwd
);
let log_ok = true;
if (log_ok) {
change_path('/' + username)
}
}
\ No newline at end of file
...@@ -112,8 +112,6 @@ app.get('/', (req, res) => { ...@@ -112,8 +112,6 @@ app.get('/', (req, res) => {
// resCode : [ 0: User now logged in, 1: False password, 2: Invalid username, 3: Empty user or pass ] // resCode : [ 0: User now logged in, 1: False password, 2: Invalid username, 3: Empty user or pass ]
app.get('/login', (req, res) => { app.get('/login', (req, res) => {
// sql.connect();
const user = req.query['user']; const user = req.query['user'];
const pass = req.query['pass']; const pass = req.query['pass'];
// userObject = sql.userExist(user, pass); // userObject = sql.userExist(user, pass);
...@@ -291,7 +289,12 @@ app.get('/download/:file_id', (req, res) => { ...@@ -291,7 +289,12 @@ app.get('/download/:file_id', (req, res) => {
* param * param
*/ */
app.get('/change-path*', (req, res) => { app.get('/change-path*', (req, res) => {
res.send(`Request for a change path (${req.params['0']})`)
content = sql.changeDirectory('a', req.params['0'],
(content) => {
res.send(content);
});
// res.send(`Request for a change path (${req.params['0']})`)
}) })
app.get('/create-path*', (req, res) => { app.get('/create-path*', (req, res) => {
......
...@@ -14,20 +14,19 @@ var con = mysql.createConnection({ ...@@ -14,20 +14,19 @@ 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
*/ */
async 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}';`;
con.query(q, function (err, result) { con.query(q, function (err, result) {
console.log(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 false; return callback(false);
} }
}); });
} }
...@@ -37,29 +36,36 @@ async function userExist(login, pass){ ...@@ -37,29 +36,36 @@ async 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}');`;
re = await userExist(login, passwd); userExist(login, passwd, (userExist) => {
if (!re){ if (!userExist){
console.log("querry"); con.query(q, (err, res) => {
con.query(q, (err, res) => { if (err) return callback(false);
if (err) return false; if (!res) {console.log(res);return callback(false);}
console.log("User", login, "inserted in the db") console.log("User", login, "inserted in the db");
return true; return callback(true);
}); });
} }
});
} }
function addPath(login, path, parent){ /**
let q = `INSERT INTO Paths VALUES ('/${login}', ${login}, ${parent});`; * 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, callback){
let q = `INSERT INTO Paths VALUES ('${path}', '${login}', ${parent});`;
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);
}); });
} }
...@@ -69,23 +75,16 @@ function addPath(login, path, parent){ ...@@ -69,23 +75,16 @@ function addPath(login, path, 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(resolve => {
a == true; insertUser(login, passwd, (insertOk) => {
console.log(insertOk);
if (insertOk) {
addPath('/'+login, login, null, (res)=>{});
console.log("Add ok");
}
}); });
} }
// 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,31 +96,59 @@ async function addUser(login, passwd){ ...@@ -97,31 +96,59 @@ async function addUser(login, passwd){
| /a/coucou/test | a | /a/coucou | NULL | NULL | | /a/coucou/test | a | /a/coucou | NULL | NULL |
+----------------+-------+-----------+---------+-----------+ +----------------+-------+-----------+---------+-----------+
*/ */
async function changeDirectory(login, path, callback){
q = `
SELECT Paths.paths, login, parent, Files.file_id, Files.file_name
FROM Paths
LEFT JOIN Files ON Files.paths = Paths.paths
WHERE Paths.login='${login}'
AND Paths.paths='${path}'
OR Paths.parent='${path}';`;
con.query(q, (err, res) => {
if (err) {
console.log("Error while loading the path");
return callback(false, err);
}
function changePath(login, path){ let content = [];
return [ for (let i in res){
{ content.push({
path: '/a/coucou', paths: res[i].paths,
login: 'a', login: res[i].login,
parent: '/a', parent: res[i].parent,
file_id: 'abnnnnn', file_id: res[i].file_id,
file_name: 'deux' file_name: res[i].file_name
}, });
{
path: '/a/coucou',
login: 'a',
parent: '/a',
file_id: 'accb',
file_name: 'trois'
},
{
path: '/a/coucou/test',
login: 'a',
parent: '/a/coucou',
file_id: 'NULL',
file_name: 'NULL'
} }
];
console.log(content);
return callback(content, "Change dir success");
});
// return [
// {
// path: '/a/coucou',
// login: 'a',
// parent: '/a',
// file_id: 'abnnnnn',
// file_name: 'deux'
// },
// {
// path: '/a/coucou',
// login: 'a',
// parent: '/a',
// file_id: 'accb',
// file_name: 'trois'
// },
// {
// path: '/a/coucou/test',
// login: 'a',
// parent: '/a/coucou',
// file_id: 'NULL',
// file_name: 'NULL'
// }
// ];
} }
// verify if a file_id is at a user // verify if a file_id is at a user
...@@ -173,4 +200,5 @@ async function addSharing(login, to_user, file_id){ ...@@ -173,4 +200,5 @@ async function addSharing(login, to_user, file_id){
exports.userExist = userExist; exports.userExist = userExist;
exports.addUser = addUser; exports.addUser = addUser;
exports.addPath = addPath; exports.addPath = addPath;
exports.addSharing = addSharing; exports.addSharing = addSharing;
\ No newline at end of file exports.changeDirectory = changeDirectory;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment