diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-14 09:40:14 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-14 09:40:14 +0200 |
commit | e42f26d37a4afee40b49aa7c1357695656acfd6c (patch) | |
tree | 9ba01584926eacd8a8011290c7cbbd9d5dd520eb /php/database.php | |
parent | e55c72279c25617f441049ab0be6fd6843eecdd5 (diff) | |
parent | c7a6eb6587b285f59a7c2c4bae9a7aa4ef8247e1 (diff) | |
download | fileup-e42f26d37a4afee40b49aa7c1357695656acfd6c.tar.gz |
Merge branch 'master' of https://github.com/alexvitkov/india
Diffstat (limited to 'php/database.php')
-rw-r--r-- | php/database.php | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/php/database.php b/php/database.php index 6762a5f..58ca251 100644 --- a/php/database.php +++ b/php/database.php @@ -458,19 +458,25 @@ require_once "node.php"; } } - function create_shared_node(string $password,int $node_id):bool + function create_shared_node(string $password,int $node_id) { - $prep=$this->pdo->prepare("insert into shared_nodes(node_id,passcode) - values (:id,:pass) + $code=$this->get_random_node_name(""); + $prep=$this->pdo->prepare("insert into shared_nodes(node_id,passcode,code) + values (:id,:pass,:code) "); $prep->bindParam(':id',$node_id); $prep->bindParam(':pass',$password); + $prep->bindParam(':code',$code); if($prep->execute()==false) { error_log("could not create shared node in create_shared_node"); - return false; + return NULL; } - return true; + $shared_node=new Shared_Node(); + $shared_node->code=$code; + $shared_node->node_id=$node_id; + $shared_node->password=$password; + return $shared_node; } function get_node(int $node_id) { @@ -588,6 +594,24 @@ require_once "node.php"; return false; } } + function get_shared_node(string $code) + { + $prepare=$this->pdo->prepare(" + select * from shared_nodes where code=:code + "); + $prepare->bindParam(':code',$code); + if($prepare->execute()==false) + { + error_log("sql statement at get_shared_node failed"); + return NULL; + } + $ret=$prepare->fetch(PDO::FETCH_ASSOC); + $nod=new Shared_Node(); + $nod->node_id=$ret["node_id"]; + $nod->password=$ret["passcode"]; + $nod->code=$ret["code"]; + return $nod; + } /*returns false if username is taken, email is not checked here*/ function register_user(string $user,string $password,string $email) : bool |