From 2840a1401cc81fb803d5ece0c6f05b0826fff4af Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 7 Jun 2017 14:53:58 +0200 Subject: [PATCH] Updated tables name --- classes/components/user.php | 28 ++++++++++++++++++++-------- classes/tokens.php | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/classes/components/user.php b/classes/components/user.php index 6c5f2d1..e431b39 100644 --- a/classes/components/user.php +++ b/classes/components/user.php @@ -12,6 +12,18 @@ class User{ */ private $userTable = "utilisateurs"; + /** + * @var String $userLoginAPItable The name of the table that contains logins performed on the API + */ + private $userLoginAPItable = ""; + + /** + * Public constructor + */ + public function __construct(){ + $this->userLoginAPItable = CS::get()->config->get("dbprefix")."API_userLoginToken"; + } + /** * Try to login user with returning a service token * @@ -49,10 +61,10 @@ class User{ $token2 = random_str(75); //Insert token in the database - $tableName = "API_userLoginToken"; + $tableName = $this->userLoginAPItable; $insertValues = array( "ID_utilisateurs" => $userID, - "ID_API_ServicesToken" => $serviceID, + "ID_".CS::get()->config->get("dbprefix")."API_ServicesToken" => $serviceID, "token1" => $token1, "token2" => $token2 ); @@ -72,12 +84,12 @@ class User{ */ public function getUserLoginTokenByIDs($userID, $serviceID){ //Prepare database request - $conditions = "WHERE ID_utilisateurs = ? AND ID_API_ServicesToken = ?"; + $conditions = "WHERE ID_utilisateurs = ? AND ID_".CS::get()->config->get("dbprefix")."API_ServicesToken = ?"; $values = array( $userID, $serviceID ); - $tokenInfos = CS::get()->db->select("API_userLoginToken", $conditions, $values); + $tokenInfos = CS::get()->db->select($this->userLoginAPItable, $conditions, $values); if(count($tokenInfos) == 0) return false; //There is nobody at this address @@ -99,14 +111,14 @@ class User{ public function deleteUserLoginToken($userID, $serviceID){ //Prepare database request - $condition = "ID_utilisateurs = ? AND ID_API_ServicesToken = ?"; + $condition = "ID_utilisateurs = ? AND ID_".CS::get()->config->get("dbprefix")."API_ServicesToken = ?"; $values = array( $userID, $serviceID ); //Try to perform request - if(!CS::get()->db->deleteEntry("API_userLoginToken", $condition, $values)) + if(!CS::get()->db->deleteEntry($this->userLoginAPItable, $condition, $values)) return false; //Something went wrong during the request //Everything is ok @@ -126,8 +138,8 @@ class User{ return 0; //Prepare database request - $tablesName = "API_userLoginToken"; - $conditions = "WHERE API_userLoginToken.ID_API_ServicesToken = ? AND API_userLoginToken.token1 = ? AND API_userLoginToken.token2 = ?"; + $tablesName = $this->userLoginAPItable; + $conditions = "WHERE ".$this->userLoginAPItable.".ID_".CS::get()->config->get("dbprefix")."API_ServicesToken = ? AND ".$this->userLoginAPItable.".token1 = ? AND ".$this->userLoginAPItable.".token2 = ?"; $conditionsValues = array( $serviceID, $tokens[0], diff --git a/classes/tokens.php b/classes/tokens.php index 7307d5b..86a064b 100644 --- a/classes/tokens.php +++ b/classes/tokens.php @@ -36,7 +36,7 @@ class Tokens{ */ private function validateClientTokens($serviceName, $token){ //Prepare DataBase request - $tableName = "API_ServicesToken"; + $tableName = CS::get()->config->get("dbprefix")."API_ServicesToken"; $conditions = "WHERE serviceName = ? AND token = ?"; $values = array( $serviceName,