From a2f3ebb6dd985e264a41638b068c125824040453 Mon Sep 17 00:00:00 2001 From: Damien Burel <damien.burel@maarch.org> Date: Mon, 3 Apr 2017 10:14:22 +0200 Subject: [PATCH] [FEAT] [PROFILE V2] Create controller (tests are coming) + route --- apps/maarch_entreprise/index.php | 18 +++++------- composer.json | 2 +- core/Controllers/UserController.php | 38 ++++++++++++++++++++++++ core/Models/UserModelAbstract.php | 45 +++++++++++++++++++++++++++++ rest/index.php | 3 ++ 5 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 core/Controllers/UserController.php diff --git a/apps/maarch_entreprise/index.php b/apps/maarch_entreprise/index.php index 13182b9cb9c..cd9d3365c87 100644 --- a/apps/maarch_entreprise/index.php +++ b/apps/maarch_entreprise/index.php @@ -387,18 +387,16 @@ if (file_exists($path)) { </div> </body> <?php -if (V2_ENABLED) { - if (PROD_MODE) { - ?> +if (PROD_MODE) { +?> <script src="js/angular/main.bundle.min.js"></script> +<?php +} else { + ?> + <script> + System.import('js/angular/main.js').catch(function(err){ console.error(err); }); + </script> <?php - } else { - ?> - <script> - System.import('js/angular/main.js').catch(function(err){ console.error(err); }); - </script> - <?php - } } ?> diff --git a/composer.json b/composer.json index 0224ab0854e..1ceae779fb4 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "psr-4": { "Core\\": "core/", "Apps\\": "apps/maarch_entreprise/", - "Attachments\\": "modules/attachments/", + "Attachments\\": "modules/attachments/", "Entities\\": "modules/entities/", "Visa\\": "modules/visa/" } diff --git a/core/Controllers/UserController.php b/core/Controllers/UserController.php new file mode 100644 index 00000000000..f214c682cc5 --- /dev/null +++ b/core/Controllers/UserController.php @@ -0,0 +1,38 @@ +<?php + +/** +* Copyright Maarch since 2008 under licence GPLv3. +* See LICENCE.txt file at the root folder for more details. +* This file is part of Maarch software. +* +*/ + +/** +* @brief User Controller +* @author dev@maarch.org +* @ingroup core +*/ + +namespace Core\Controllers; + +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Respect\Validation\Validator; +use Core\Models\UserModel; + +class UserController +{ + public function getCurrentUserInfos(RequestInterface $request, ResponseInterface $response) + { + if (empty($_SESSION['user']['UserId'])) { + return $response->withStatus(401)->withJson(['errors' => 'User Not Connected']); + } + + $user = UserModel::getById(['userId' => $_SESSION['user']['UserId'], 'select' => ['user_id', 'firstname', 'lastname', 'phone', 'mail', 'initials']]); + $user['signatures'] = UserModel::getSignaturesById(['userId' => $_SESSION['user']['UserId']]); + $user['emailSignatures'] = UserModel::getEmailSignaturesById(['userId' => $_SESSION['user']['UserId']]); + + return $response->withJson($user); + } + +} diff --git a/core/Models/UserModelAbstract.php b/core/Models/UserModelAbstract.php index 3da01862be3..9cb7d33d46a 100644 --- a/core/Models/UserModelAbstract.php +++ b/core/Models/UserModelAbstract.php @@ -34,4 +34,49 @@ class UserModelAbstract extends \Apps_Table_Service return $aReturn; } + + public static function getById(array $aArgs = []) + { + static::checkRequired($aArgs, ['userId']); + static::checkString($aArgs, ['userId']); + + $aReturn = static::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['users'], + 'where' => ['user_id = ?'], + 'data' => [$aArgs['userId']], + ]); + + return $aReturn[0]; + } + + public static function getSignaturesById(array $aArgs = []) + { + static::checkRequired($aArgs, ['userId']); + static::checkString($aArgs, ['userId']); + + $aReturn = static::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['user_signatures'], + 'where' => ['user_id = ?'], + 'data' => [$aArgs['userId']], + ]); + + return $aReturn; + } + + public static function getEmailSignaturesById(array $aArgs = []) + { + static::checkRequired($aArgs, ['userId']); + static::checkString($aArgs, ['userId']); + + $aReturn = static::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['users_email_signatures'], + 'where' => ['user_id = ?'], + 'data' => [$aArgs['userId']], + ]); + + return $aReturn; + } } diff --git a/rest/index.php b/rest/index.php index a163b6af732..fdbfa80bcd0 100644 --- a/rest/index.php +++ b/rest/index.php @@ -131,4 +131,7 @@ $app->get('/res/{resId}/notes/count', \Core\Controllers\ResController::class . ' //extresource $app->post('/resExt', \Core\Controllers\ResExtController::class . ':create'); +//Users +$app->get('/user/profile', \Core\Controllers\UserController::class . ':getCurrentUserInfos'); + $app->run(); -- GitLab