ljoaquim 5 mesi fa
parent
commit
406a85ff68
4 ha cambiato i file con 9 aggiunte e 9 eliminazioni
  1. 5 5
      bin/setup
  2. 1 1
      migrations/migrations_v1.sql
  3. 1 1
      models/ApiUserModel.php
  4. 2 2
      models/UserModel.php

+ 5 - 5
bin/setup

@@ -5,12 +5,12 @@ DB_FILE="test.db"
 
 # Executa comandos SQL no SQLite
 sqlite3 "$DB_FILE" <<EOF
--- Cria tabela 'user' se não existir, com coluna 'password'
+-- Cria tabela 'user' se não existir, com coluna 'user_password'
 CREATE TABLE IF NOT EXISTS user (
     user_id INTEGER PRIMARY KEY AUTOINCREMENT,
     user_name TEXT NOT NULL,
     user_flag TEXT NOT NULL,
-    password TEXT NOT NULL  -- Nova coluna para senha hasheada
+    user_password TEXT NOT NULL  -- Nova coluna para senha hasheada
 );
 
 -- Cria tabela 'api_key' se não existir
@@ -23,8 +23,8 @@ CREATE TABLE IF NOT EXISTS api_key (
 );
 
 -- Insere usuário de exemplo ('admin') com senha hasheada se não existir
--- Hash de 'pass' (gere com password_hash em PHP e substitua)
-INSERT OR IGNORE INTO user (user_name, user_flag, password) VALUES ('admin', 'a', '\$2y\$10\$K.0XhB3kXjZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZ');
+-- Hash de 'pass' (gere com user_password_hash em PHP e substitua)
+INSERT OR IGNORE INTO user (user_name, user_flag, user_password) VALUES ('admin', 'a', '\$2y\$10\$K.0XhB3kXjZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZ');
 
 -- Insere chave API para o usuário 'admin' se não existir
 INSERT OR IGNORE INTO api_key (user_id, api_key_user, api_key_secret)
@@ -32,7 +32,7 @@ SELECT user_id, 'myapikey', 'myapisecret' FROM user WHERE user_name = 'admin';
 
 -- Opcional: Insere mais um usuário de teste com senha hasheada
 -- Hash de 'testpass' (substitua pelo real)
-INSERT OR IGNORE INTO user (user_name, user_flag, password) VALUES ('testuser', 'a', '\$2y\$10\$AnotherHashHereForTestPass');
+INSERT OR IGNORE INTO user (user_name, user_flag, user_password) VALUES ('testuser', 'a', '\$2y\$10\$AnotherHashHereForTestPass');
 INSERT OR IGNORE INTO api_key (user_id, api_key_user, api_key_secret)
 SELECT user_id, 'testapikey', 'testapisecret' FROM user WHERE user_name = 'testuser';
 

+ 1 - 1
migrations/migrations_v1.sql

@@ -4,7 +4,7 @@ CREATE TABLE user (
     user_id INTEGER PRIMARY KEY AUTOINCREMENT,
     user_name TEXT NOT NULL,
     user_flag TEXT NOT NULL,
-    password TEXT NOT NULL  -- Nova coluna para senha hasheada
+    user_password TEXT NOT NULL  -- Nova coluna para senha hasheada
 );
 
 CREATE TABLE api_key (

+ 1 - 1
models/ApiUserModel.php

@@ -10,7 +10,7 @@ class ApiUserModel
     public function __construct()
     {
         // Conecta ao DB usando variável do .env
-        $dbFile = $_ENV['DB_FILE'] ?? 'bridge.db';
+        $dbFile = $_ENV['DB_FILE'];
         $dbPath = __DIR__ . '/../' . $dbFile;
         $this->pdo = new \PDO("sqlite:" . $dbPath);
         $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

+ 2 - 2
models/UserModel.php

@@ -9,7 +9,7 @@ class UserModel
     public function __construct()
     {
         // Conecta ao DB usando variável do .env
-        $dbFile = $_ENV['DB_FILE'] ?? 'bridge.db';
+        $dbFile = $_ENV['DB_FILE'];
         $dbPath = __DIR__ . '/../' . $dbFile;
         $this->pdo = new \PDO("sqlite:" . $dbPath);
         $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
@@ -56,7 +56,7 @@ class UserModel
         $hash = password_hash($password, PASSWORD_DEFAULT);
 
         // Insere usuário
-        $stmt = $this->pdo->prepare("INSERT INTO user (user_name, user_flag, password) VALUES (:username, :flag, :hash)");
+        $stmt = $this->pdo->prepare("INSERT INTO user (user_name, user_flag, user_password) VALUES (:username, :flag, :hash)");
         if (!$stmt->execute(['username' => $username, 'flag' => $flag, 'hash' => $hash])) {
             return false;
         }