tinyqc/app/Database/Migrations/2026-02-09-000001_Users.php
mahdahar 87ff4c8d85 feat: Add user authentication system and secure all routes
- Implement AuthController with login/logout functionality
- Create UsersModel with bcrypt password hashing
- Add AuthFilter to protect all application routes
- Create login page with error handling
- Add users database migration with email/username fields
- Rename ResultComments to TestComments for consistency
- Update all routes to require authentication filter
- Enhance EntryApiController with comment deletion and better error handling
- Update seeder to include demo users and improved test data
- Fix BaseController to handle auth sessions properly
- Update entry views (daily/monthly) with new API endpoints
- Update layout with logout button and user info display
- Refactor control test index view for better organization
2026-02-09 11:12:12 +07:00

34 lines
1.2 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class Users extends Migration
{
public function up()
{
$this->forge->addField([
'user_id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'username' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false],
'password' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false],
'remember_token' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'created_at' => ['type' => 'DATETIME', 'null' => true],
'updated_at' => ['type' => 'DATETIME', 'null' => true],
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addKey('user_id', true);
$this->forge->addUniqueKey('username');
$this->forge->createTable('master_users');
// Insert default admin user
$password = password_hash('admin123', PASSWORD_DEFAULT);
$this->db->query("INSERT INTO master_users (username, password, created_at, updated_at) VALUES ('admin', '{$password}', NOW(), NOW())");
}
public function down()
{
$this->forge->dropTable('master_users', true);
}
}