diff --git a/classes/Users.php b/classes/Users.php index 5d520f4..ffeac32 100644 --- a/classes/Users.php +++ b/classes/Users.php @@ -142,18 +142,20 @@ public function does_fb_id_exist($flo_id){ public function doInitialUserHandling($flo_id) { -//CAREFUL this will update the username with FLO ID FOR NEW USERS -// If username exists then do only FLO ID insertion + +// If username exists only then do FLO ID insertion if ($this->databaseConnection()) { $now = $this->time_now(); - $query = $this->db_connection->prepare("SELECT * FROM $this->customers_table WHERE `flo_id`=:flo_id"); + +// I have added LIMIT 1 .. so only the first FLO ID is allowed. If there are two FLO IDs for same user, the second one will be discarded. MAYBE I SHOULD ADD AN EXPLICT CHECK LATER FOR DUPLICATE FLO ID WHILE BEING INSERTED + $query = $this->db_connection->prepare("SELECT * FROM $this->customers_table WHERE `flo_id`=:flo_id LIMIT 1"); $query->bindValue(':flo_id', $flo_id, PDO::PARAM_STR); $query->execute(); $rowCount = $query->rowCount(); if($rowCount) { - + //The case where FLO ID exists in database $user_obj = $query->fetchObject(); $update_query = $this->db_connection->prepare("UPDATE $this->customers_table @@ -164,11 +166,8 @@ public function does_fb_id_exist($flo_id){ $update_query->execute(); $_SESSION['user_id'] = $user_obj->CustomerId; - // $_SESSION['user_name'] = $user_obj->Username; - // $_SESSION['email'] = $user_obj->Email; - $_SESSION['user_name'] = $flo_id; - $_SESSION['email'] = $flo_id; - + $_SESSION['user_name'] = $user_obj->Username; + $_SESSION['email'] = $user_obj->Email; if (!isset($_SESSION['last_trade_date'])) { @@ -178,24 +177,31 @@ public function does_fb_id_exist($flo_id){ } else { - //NOT NEEDED - //$this->user_name = $_SESSION['first_name'].time(); + //The case when FLO ID does not exist in database + //NOT NEEDED .. These session variables are set in authenticateMe.php + $this->user_name = $flo_id.time(); + // $this->user_name = $_SESSION['first_name'].time(); + //$this->name = $_SESSION['full_name']; - //$this->email = $_SESSION['email']; + // $this->email = $_SESSION['email']; + $this->email = (isset($_SESSION['email'])) ? $_SESSION['email'] : ""; $query = $this->db_connection->prepare(" INSERT INTO $this->customers_table (`CustomerId`, `flo_id`, `Username`, `Email`, `Name`, `UpdateDate`, `InsertDate`, `SaveDate`, `is_active`) - VALUES ('',:flo_id,:flo_id,:flo_id,:flo_id,NULL,'$now',NULL,0) + VALUES ('',:flo_id,:Username,:Email,:flo_id,NULL,'$now',NULL,0) "); +// Here we are setting name = FLO ID. Later we can ask for actual name and email when user logs in second time if both are same, and update +//Also email will be blank here for first time FLO user. That will give a signature to update the email later. + $query->bindValue(':flo_id', $flo_id, PDO::PARAM_INT); $query->bindValue(':Username', $this->user_name, PDO::PARAM_STR); $query->bindValue(':Email', $this->email, PDO::PARAM_STR); $query->bindValue(':Name', $this->name, PDO::PARAM_STR); if($query->execute()) { $_SESSION['user_id'] = $this->db_connection->lastInsertId(); - // $_SESSION['user_name'] = $this->user_name; - $_SESSION['user_name'] = $flo_id; + $_SESSION['user_name'] = $this->user_name; + $AssetTypeId = 'btc'; $Balance = 0.00; $FrozenBalance = 0.00; @@ -269,7 +275,7 @@ public function checkIfFloIDPermitted($flo_id){ return false; } -public function insert_floPublicKey($flo_id, $floPublicKey) { +public function update_floPublicKey($flo_id, $floPublicKey) { if ($this->databaseConnection()) { @@ -294,7 +300,7 @@ public function insert_floPublicKey($flo_id, $floPublicKey) { } -public function insert_flo_details($floID, $auth_random, $floPublicKey) { +public function update_flo_details($floID, $auth_random, $floPublicKey) { $now = $this->time_now(); if ($this->databaseConnection()) { @@ -437,6 +443,22 @@ public function insert_flo_details($floID, $auth_random, $floPublicKey) { return false; } + public function getUserID($flo_id) { + + if ($this->databaseConnection()) { + $customerId = (int) $customerId; + $query = $this->db_connection->prepare("SELECT CustomerId FROM ".USERS_TABLE." WHERE flo_id = :id LIMIT 1"); + $query->bindParam('id', $flo_id); + + $query->execute(); + $row_count = $query->rowCount(); + if ($row_count == 1) { + return $query->fetchObject()->CustomerId; + } + } + return false; + } + public function input_user_email($email=null, $user_id=null) { if ($this->databaseConnection()) { $query = $this->db_connection->prepare("