Premier commit

This commit is contained in:
2024-09-09 10:22:45 +02:00
commit bcc2604080
74 changed files with 25819 additions and 0 deletions

34
cli/init_assistant.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
if (PHP_SAPI != 'cli') {
exit('PHP SAPI must be cli');
}
require(__DIR__ . '/../vendor/autoload.php');
foreach (require __DIR__ . '/../env.php' as $key => $val) {
putenv("{$key}={$val}");
}
$db = new PDO('sqlite:' . getenv('SQLITE_DB'));
$query =<<<SQL
CREATE TABLE IF NOT EXISTS "chat_assistant" (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
title VARCHAR(255) NOT NULL,
model VARCHAR(64) NOT NULL,
system_prompt TEXT NOT NULL,
temperature REAL NOT NULL DEFAULT 0,
top_p REAL NOT NULL 0,
"default" INTEGER NOT NULL DEFAULT 0,
foreign key (user_id) references "user" (id) on delete cascade on update cascade
);
SQL;
if ($db->exec($query) === false) {
$error = $db->errorInfo();
throw new RuntimeException("Query failed with error : {$error[2]}");
}
echo "Assistant table created.\n";

52
cli/init_user.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
if (PHP_SAPI != 'cli') {
exit('PHP SAPI must be cli');
}
use app\modules\user\models\User;
use app\modules\user\Rbac;
require(__DIR__ . '/../vendor/autoload.php');
foreach (require __DIR__ . '/../env.php' as $key => $val) {
putenv("{$key}={$val}");
}
$db = new PDO('sqlite:' . getenv('SQLITE_DB'));
Rbac::$db = $db;
$query = file_get_contents(__DIR__ . '/../modules/user/sql/install-sqlite.sql');
if ($db->exec($query) === false) {
$error = $db->errorInfo();
throw new RuntimeException("Query failed with error : {$error[2]}");
}
echo "Users table created.\n";
echo "Create admin user\n";
$name = readline("Nom : ");
$email = readline("Email : ");
$username = readline("Nom d'utilisateur : ");
$password = readline("Mot de passe : ");
$user = new User($db);
$user->bind([
'name' => $name,
'username' => $username,
'email' => $email,
'password' => $password,
]);
if ($user->save()) {
echo "Utilisateur $username créé.\n";
}
if (!Rbac::roleExists('admin')) {
Rbac::createRole('admin');
}
Rbac::assignRole($user->id, 'admin');