Skip to content
Snippets Groups Projects
Verified Commit ba1a174e authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #16831 TIME 1:45 Can set/get x509Fingerprint in users API + doc

parent 51577494
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,7 @@ class UserController ...@@ -46,7 +46,7 @@ class UserController
{ {
$queryParams = $request->getQueryParams(); $queryParams = $request->getQueryParams();
$select = ['id', 'firstname', 'lastname', 'substitute']; $select = ['id', 'firstname', 'lastname', 'substitute', 'x509_fingerprint'];
$where = []; $where = [];
$queryData = []; $queryData = [];
if (empty($queryParams['mode'])) { if (empty($queryParams['mode'])) {
...@@ -65,8 +65,14 @@ class UserController ...@@ -65,8 +65,14 @@ class UserController
'orderBy' => ['lastname', 'firstname'] 'orderBy' => ['lastname', 'firstname']
]); ]);
$currentUser = UserModel::getById(['select' => ['"isRest"'], 'id' => $GLOBALS['id']]);
foreach ($users as $key => $user) { foreach ($users as $key => $user) {
$users[$key]['substitute'] = !empty($user['substitute']); $users[$key]['substitute'] = !empty($user['substitute']);
if ($currentUser['isRest']) {
$users[$key]['x509Fingerprint'] = $users[$key]['x509_fingerprint'];
}
unset($users[$key]['x509_fingerprint']);
} }
return $response->withJson(['users' => $users]); return $response->withJson(['users' => $users]);
...@@ -125,6 +131,8 @@ class UserController ...@@ -125,6 +131,8 @@ class UserController
return $response->withStatus(400)->withJson(['errors' => 'Body lastname is empty or not a string']); return $response->withStatus(400)->withJson(['errors' => 'Body lastname is empty or not a string']);
} elseif (empty($body['email']) || !filter_var($body['email'], FILTER_VALIDATE_EMAIL) || !Validator::stringType()->notEmpty()->length(1, 128)->validate($body['email'])) { } elseif (empty($body['email']) || !filter_var($body['email'], FILTER_VALIDATE_EMAIL) || !Validator::stringType()->notEmpty()->length(1, 128)->validate($body['email'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body email is empty or not a valid email']); return $response->withStatus(400)->withJson(['errors' => 'Body email is empty or not a valid email']);
} elseif (!empty($body['x509Fingerprint']) && !Validator::stringType()->validate($body['x509Fingerprint'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body x509Fingerprint is not a string']);
} }
$body['login'] = strtolower($body['login']); $body['login'] = strtolower($body['login']);
...@@ -132,6 +140,8 @@ class UserController ...@@ -132,6 +140,8 @@ class UserController
if (!empty($existingUser)) { if (!empty($existingUser)) {
return $response->withStatus(400)->withJson(['errors' => 'Login already exists', 'lang' => 'userLoginAlreadyExists']); return $response->withStatus(400)->withJson(['errors' => 'Login already exists', 'lang' => 'userLoginAlreadyExists']);
} }
$body['x509_fingerprint'] = $body['x509Fingerprint'];
if (!empty($body['isRest'])) { if (!empty($body['isRest'])) {
$body['"isRest"'] = true; $body['"isRest"'] = true;
...@@ -191,6 +201,8 @@ class UserController ...@@ -191,6 +201,8 @@ class UserController
return $response->withStatus(400)->withJson(['errors' => 'Body lastname is empty or not a string']); return $response->withStatus(400)->withJson(['errors' => 'Body lastname is empty or not a string']);
} elseif (empty($body['email']) || !filter_var($body['email'], FILTER_VALIDATE_EMAIL) || !Validator::stringType()->notEmpty()->length(1, 128)->validate($body['email'])) { } elseif (empty($body['email']) || !filter_var($body['email'], FILTER_VALIDATE_EMAIL) || !Validator::stringType()->notEmpty()->length(1, 128)->validate($body['email'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body email is empty or not a valid email']); return $response->withStatus(400)->withJson(['errors' => 'Body email is empty or not a valid email']);
} elseif (!empty($body['x509Fingerprint']) && !Validator::stringType()->validate($body['x509Fingerprint'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body x509Fingerprint is not a string']);
} }
$user = UserModel::getById(['id' => $args['id'], 'select' => [1]]); $user = UserModel::getById(['id' => $args['id'], 'select' => [1]]);
...@@ -205,6 +217,11 @@ class UserController ...@@ -205,6 +217,11 @@ class UserController
'signature_modes' => [] 'signature_modes' => []
]; ];
$currentUser = UserModel::getById(['select' => ['"isRest"'], 'id' => $GLOBALS['id']]);
if ($currentUser['isRest']) {
$set['x509_fingerprint'] = $body['x509Fingerprint'];
}
if (!empty($body['signatureModes'])) { if (!empty($body['signatureModes'])) {
if (!Validator::arrayType()->validate($body['signatureModes'])) { if (!Validator::arrayType()->validate($body['signatureModes'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body signatureModes is not an array']); return $response->withStatus(400)->withJson(['errors' => 'Body signatureModes is not an array']);
...@@ -710,7 +727,7 @@ class UserController ...@@ -710,7 +727,7 @@ class UserController
ValidatorModel::notEmpty($args, ['id']); ValidatorModel::notEmpty($args, ['id']);
ValidatorModel::intVal($args, ['id']); ValidatorModel::intVal($args, ['id']);
$user = UserModel::getById(['select' => ['id', 'login', 'email', 'firstname', 'lastname', 'picture', 'preferences', 'substitute', '"isRest"', 'signature_modes'], 'id' => $args['id']]); $user = UserModel::getById(['select' => ['id', 'login', 'email', 'firstname', 'lastname', 'picture', 'preferences', 'substitute', '"isRest"', 'signature_modes', 'x509_fingerprint'], 'id' => $args['id']]);
if (empty($user)) { if (empty($user)) {
return []; return [];
} }
...@@ -736,6 +753,12 @@ class UserController ...@@ -736,6 +753,12 @@ class UserController
} }
} }
$currentUser = UserModel::getById(['select' => ['"isRest"'], 'id' => $GLOBALS['id']]);
if ($currentUser['isRest']) {
$user['x509Fingerprint'] = $user['x509_fingerprint'];
}
unset($user['x509_fingerprint']);
return $user; return $user;
} }
} }
...@@ -80,7 +80,7 @@ class UserModel ...@@ -80,7 +80,7 @@ class UserModel
public static function create(array $args) public static function create(array $args)
{ {
ValidatorModel::notEmpty($args, ['login', 'email', 'firstname', 'lastname', 'picture']); ValidatorModel::notEmpty($args, ['login', 'email', 'firstname', 'lastname', 'picture']);
ValidatorModel::stringType($args, ['login', 'email', 'firstname', 'lastname', 'picture', 'mode', 'signatureModes']); ValidatorModel::stringType($args, ['login', 'email', 'firstname', 'lastname', 'picture', 'mode', 'signatureModes', 'x509_fingerprint']);
if (empty($args['password'])) { if (empty($args['password'])) {
$args['password'] = AuthenticationModel::generatePassword(); $args['password'] = AuthenticationModel::generatePassword();
...@@ -99,7 +99,8 @@ class UserModel ...@@ -99,7 +99,8 @@ class UserModel
'"isRest"' => empty($args['isRest']) ? 'false' : 'true', '"isRest"' => empty($args['isRest']) ? 'false' : 'true',
'picture' => $args['picture'], 'picture' => $args['picture'],
'password_modification_date' => 'CURRENT_TIMESTAMP', 'password_modification_date' => 'CURRENT_TIMESTAMP',
'signature_modes' => $args['signatureModes'] 'signature_modes' => $args['signatureModes'],
'x509_fingerprint' => $args['x509_fingerprint'],
] ]
]); ]);
......
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