Skip to content
Snippets Groups Projects
Commit a2f3ebb6 authored by Damien's avatar Damien
Browse files

[FEAT] [PROFILE V2] Create controller (tests are coming) + route

parent 4a9136dd
No related branches found
No related tags found
No related merge requests found
...@@ -387,18 +387,16 @@ if (file_exists($path)) { ...@@ -387,18 +387,16 @@ if (file_exists($path)) {
</div> </div>
</body> </body>
<?php <?php
if (V2_ENABLED) { if (PROD_MODE) {
if (PROD_MODE) { ?>
?>
<script src="js/angular/main.bundle.min.js"></script> <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 <?php
} else {
?>
<script>
System.import('js/angular/main.js').catch(function(err){ console.error(err); });
</script>
<?php
}
} }
?> ?>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"psr-4": { "psr-4": {
"Core\\": "core/", "Core\\": "core/",
"Apps\\": "apps/maarch_entreprise/", "Apps\\": "apps/maarch_entreprise/",
"Attachments\\": "modules/attachments/", "Attachments\\": "modules/attachments/",
"Entities\\": "modules/entities/", "Entities\\": "modules/entities/",
"Visa\\": "modules/visa/" "Visa\\": "modules/visa/"
} }
......
<?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);
}
}
...@@ -34,4 +34,49 @@ class UserModelAbstract extends \Apps_Table_Service ...@@ -34,4 +34,49 @@ class UserModelAbstract extends \Apps_Table_Service
return $aReturn; 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;
}
} }
...@@ -131,4 +131,7 @@ $app->get('/res/{resId}/notes/count', \Core\Controllers\ResController::class . ' ...@@ -131,4 +131,7 @@ $app->get('/res/{resId}/notes/count', \Core\Controllers\ResController::class . '
//extresource //extresource
$app->post('/resExt', \Core\Controllers\ResExtController::class . ':create'); $app->post('/resExt', \Core\Controllers\ResExtController::class . ':create');
//Users
$app->get('/user/profile', \Core\Controllers\UserController::class . ':getCurrentUserInfos');
$app->run(); $app->run();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment