Fix console command to update/create a user.

This commit is contained in:
osaajani 2021-08-05 17:14:53 +02:00
parent 85095ef995
commit 850923c1e6
2 changed files with 19 additions and 4 deletions

View File

@ -81,6 +81,21 @@ namespace controllers\internals;
exit($user ? 0 : 1);
}
/**
* Check if a user exists based on id.
*
* @param string $id : User id
*/
public function user_id_exists(string $id)
{
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
$internal_user = new \controllers\internals\User($bdd);
$user = $internal_user->get($id);
exit($user ? 0 : 1);
}
/**
* Create a user or update an existing user.
@ -103,7 +118,7 @@ namespace controllers\internals;
if ($user)
{
$api_key = $api_key ?? $internal_user->generate_random_api_key();
$user = [
$update_datas = [
'email' => $email,
'password' => $encrypt_password ? password_hash($password, PASSWORD_DEFAULT) : $password,
'admin' => $admin,
@ -111,7 +126,7 @@ namespace controllers\internals;
'status' => $status,
];
$success = $internal_user->update($user['id'], $user);
$success = $internal_user->update($user['id'], $update_datas);
echo json_encode(['id' => $user['id']]);
exit($success ? 0 : 1);

View File

@ -94,10 +94,10 @@ jQuery(document).ready(function ()
},
},
{data: 'at', render: jQuery.fn.dataTable.render.text()},
{data: 'text', render: jQuery.fn.dataTable.render.text()},
{data: 'text', render: jQuery.fn.dataTable.render.text()}
<?php if ($_SESSION['user']['admin']) { ?>
{
,{
data: 'id',
render: function (data, type, row, meta) {
return '<input name="ids[]" type="checkbox" value="' + data + '">';