Update user creation to allow using already encrypted password

This commit is contained in:
osaajani 2020-04-08 23:34:15 +02:00
parent 6f1c726284
commit 3569baf1a1
2 changed files with 12 additions and 7 deletions

View file

@ -67,8 +67,11 @@ namespace controllers\internals;
* @param $admin : Is user admin
* @param $api_key : User API key, if null random api key is generated
* @param $status : User status, default \models\User::STATUS_ACTIVE
* @param bool $encrypt_password : Should the password be encrypted, by default true
*
* @return exit code 0 on success | 1 on error
*/
public function create_update_user(string $email, string $password, bool $admin, ?string $api_key = null, string $status = \models\User::STATUS_ACTIVE)
public function create_update_user(string $email, string $password, bool $admin, ?string $api_key = null, string $status = \models\User::STATUS_ACTIVE, bool $encrypt_password = true)
{
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
$internal_user = new \controllers\internals\User($bdd);
@ -77,12 +80,12 @@ namespace controllers\internals;
if ($user)
{
$api_key = $api_key ?? $internal_user->generate_random_api_key();
$success = $internal_user->update($user['id'], $email, $password, $admin, $api_key, $status);
$success = $internal_user->update($user['id'], $email, $password, $admin, $api_key, $status, $encrypt_password);
exit($success ? 0 : 1);
}
$success = $internal_user->create($email, $password, $admin, $api_key, $status);
$success = $internal_user->create($email, $password, $admin, $api_key, $status, $encrypt_password);
exit($success ? 0 : 1);
}