mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-22 09:26:27 +02:00
fix rights
This commit is contained in:
parent
d799427993
commit
9bf1433d2e
270 changed files with 15 additions and 3 deletions
17
controllers/internals/Console.php
Executable file → Normal file
17
controllers/internals/Console.php
Executable file → Normal file
|
@ -61,18 +61,29 @@ namespace controllers\internals;
|
|||
|
||||
|
||||
/**
|
||||
* Create a user
|
||||
* Create a user or update an existing user
|
||||
* @param $email : User email
|
||||
* @param $password : User password
|
||||
* @param $admin : Is user admin
|
||||
* @param $api_key : User API key, if null random api key is generated
|
||||
* @return void : exit status 1 on error, else 0
|
||||
*/
|
||||
public function create_user (string $email, string $password, bool $admin, ?string $api_key = null)
|
||||
public function create_update_user (string $email, string $password, bool $admin, ?string $api_key = null)
|
||||
{
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
||||
$internal_user = new \controllers\internals\User($bdd);
|
||||
|
||||
$user = $internal_user->get_by_email($email);
|
||||
if ($user)
|
||||
{
|
||||
$api_key = $api_key ?? $internal_user->generate_random_api_key();
|
||||
$success = $internal_user->update($user['id'], $email, $password, $admin, $api_key);
|
||||
|
||||
exit($success ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
$success = $internal_user->create($email, $password, $admin, $api_key);
|
||||
exit ((int) !$success);
|
||||
exit($success ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue