Fix console command to update/create a user.
This commit is contained in:
parent
85095ef995
commit
850923c1e6
|
@ -81,6 +81,21 @@ namespace controllers\internals;
|
||||||
|
|
||||||
exit($user ? 0 : 1);
|
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.
|
* Create a user or update an existing user.
|
||||||
|
@ -103,7 +118,7 @@ namespace controllers\internals;
|
||||||
if ($user)
|
if ($user)
|
||||||
{
|
{
|
||||||
$api_key = $api_key ?? $internal_user->generate_random_api_key();
|
$api_key = $api_key ?? $internal_user->generate_random_api_key();
|
||||||
$user = [
|
$update_datas = [
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'password' => $encrypt_password ? password_hash($password, PASSWORD_DEFAULT) : $password,
|
'password' => $encrypt_password ? password_hash($password, PASSWORD_DEFAULT) : $password,
|
||||||
'admin' => $admin,
|
'admin' => $admin,
|
||||||
|
@ -111,7 +126,7 @@ namespace controllers\internals;
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
];
|
];
|
||||||
|
|
||||||
$success = $internal_user->update($user['id'], $user);
|
$success = $internal_user->update($user['id'], $update_datas);
|
||||||
echo json_encode(['id' => $user['id']]);
|
echo json_encode(['id' => $user['id']]);
|
||||||
|
|
||||||
exit($success ? 0 : 1);
|
exit($success ? 0 : 1);
|
||||||
|
|
|
@ -94,10 +94,10 @@ jQuery(document).ready(function ()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{data: 'at', render: jQuery.fn.dataTable.render.text()},
|
{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']) { ?>
|
<?php if ($_SESSION['user']['admin']) { ?>
|
||||||
{
|
,{
|
||||||
data: 'id',
|
data: 'id',
|
||||||
render: function (data, type, row, meta) {
|
render: function (data, type, row, meta) {
|
||||||
return '<input name="ids[]" type="checkbox" value="' + data + '">';
|
return '<input name="ids[]" type="checkbox" value="' + data + '">';
|
||||||
|
|
Loading…
Reference in New Issue