From 97d7825426a2f6b84a6684511cefedcbdc0af71e Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 3 Jun 2017 14:24:45 +0200 Subject: [PATCH] Transformed user class as components class --- RestControllers/userController.php | 6 +++--- classes/{ => components}/user.php | 5 ++++- index.php | 2 +- init.php | 5 ----- 4 files changed, 8 insertions(+), 10 deletions(-) rename classes/{ => components}/user.php (99%) diff --git a/RestControllers/userController.php b/RestControllers/userController.php index 9aa31ad..7435e3d 100644 --- a/RestControllers/userController.php +++ b/RestControllers/userController.php @@ -28,7 +28,7 @@ class userController $userPassword = $_POST['userPassword']; //Try to perform login - $loginTokens = CS::get()->user->generateUserLoginTokens($userMail, $userPassword, APIServiceID, $db); + $loginTokens = CS::get()->components->user->generateUserLoginTokens($userMail, $userPassword, APIServiceID, $db); if(!$loginTokens) throw new RestException(401, "Invalid e-mail address / password !"); @@ -53,7 +53,7 @@ class userController user_login_required(); //Try to delete token - if(!CS::get()->user->deleteUserLoginToken(userID, APIServiceID)) + if(!CS::get()->components->user->deleteUserLoginToken(userID, APIServiceID)) throw new RestException(500, "Something went wrong while trying to logout user !"); //Everything is ok @@ -91,7 +91,7 @@ class userController Rest_fatal_error(400, "Please specify at least one user ID !"); //Try to get user infos - $userInfos = CS::get()->user->getMultipleUserInfos($usersID); + $userInfos = CS::get()->components->user->getMultipleUserInfos($usersID); //Check if response is empty if(count($userInfos) == 0) diff --git a/classes/user.php b/classes/components/user.php similarity index 99% rename from classes/user.php rename to classes/components/user.php index bcf4724..ec73560 100644 --- a/classes/user.php +++ b/classes/components/user.php @@ -242,4 +242,7 @@ class User{ return crypt(sha1($userPassword), sha1($userPassword)); } -} \ No newline at end of file +} + +//Register class +Components::register("user", new User()); \ No newline at end of file diff --git a/index.php b/index.php index 22e8469..2458419 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ if(!$cs->tokens->checkClientRequestTokens()) //Check if login tokens where specified if(isset($_POST['userToken1']) AND isset($_POST['userToken2'])){ //Try to login user - $userID = $cs->user->getUserIDfromToken(APIServiceID, array( + $userID = $cs->components->user->getUserIDfromToken(APIServiceID, array( $_POST['userToken1'], $_POST['userToken2'] )); diff --git a/init.php b/init.php index 12f5c2b..e5fa7a5 100644 --- a/init.php +++ b/init.php @@ -51,11 +51,6 @@ $tokens = new Tokens(); $cs->register("tokens", $tokens); unset($tokens); -//Add user object -$user = new User(); -$cs->register("user", $user); -unset($user); - //Include components foreach(glob(PROJECT_PATH."classes/components/*.php") as $classFile){ require_once $classFile;