First Commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateUsersTable
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('users')) {
|
||||
Capsule::schema()->create('users', function (Blueprint $table) {
|
||||
$table->increments('users_id');
|
||||
$table->string('users_name');
|
||||
$table->string('users_email')->unique();
|
||||
$table->string('users_password');
|
||||
$table->string('users_role')->default('user'); // super_admin, admin, member, user
|
||||
$table->integer('users_bus_id')->default(0)->index();
|
||||
$table->string('users_avatar')->nullable();
|
||||
$table->text('users_bio')->nullable();
|
||||
$table->string('users_phone')->nullable();
|
||||
$table->timestamp('users_email_verified_at')->nullable();
|
||||
$table->timestamp('users_last_login_at')->nullable();
|
||||
$table->string('users_status')->default('active'); // active, inactive, banned
|
||||
$table->json('users_preferences')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Capsule::schema()->dropIfExists('users');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateAuthPermissionsTables
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// User Permissions
|
||||
if (!Capsule::schema()->hasTable('user_permissions')) {
|
||||
Capsule::schema()->create('user_permissions', function (Blueprint $table) {
|
||||
$table->increments('user_permissions_id');
|
||||
$table->integer('user_permissions_user_id')->unsigned();
|
||||
$table->integer('user_permissions_bus_id')->unsigned()->nullable(); // Permission might be global or company specific
|
||||
$table->string('user_permissions_permission');
|
||||
$table->integer('user_permissions_granted_by')->unsigned()->nullable();
|
||||
$table->timestamp('user_permissions_granted_at')->useCurrent();
|
||||
$table->timestamp('user_permissions_expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_permissions_user_id')->references('users_id')->on('users')->onDelete('cascade');
|
||||
// Optional: foreign key for bus_id if module order permits
|
||||
});
|
||||
}
|
||||
|
||||
// Role Permissions
|
||||
if (!Capsule::schema()->hasTable('role_permissions')) {
|
||||
Capsule::schema()->create('role_permissions', function (Blueprint $table) {
|
||||
$table->increments('role_permissions_id');
|
||||
$table->string('role_permissions_role');
|
||||
$table->integer('role_permissions_bus_id')->unsigned()->nullable();
|
||||
$table->string('role_permissions_permission');
|
||||
$table->integer('role_permissions_created_by')->unsigned()->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
// Activity Logs
|
||||
if (!Capsule::schema()->hasTable('activity_logs')) {
|
||||
Capsule::schema()->create('activity_logs', function (Blueprint $table) {
|
||||
$table->increments('activity_logs_id');
|
||||
$table->integer('activity_logs_user_id')->unsigned()->nullable();
|
||||
$table->integer('activity_logs_bus_id')->unsigned()->nullable();
|
||||
$table->string('activity_logs_action');
|
||||
$table->string('activity_logs_resource_type')->nullable();
|
||||
$table->string('activity_logs_resource_id')->nullable();
|
||||
$table->json('activity_logs_old_values')->nullable();
|
||||
$table->json('activity_logs_new_values')->nullable();
|
||||
$table->string('activity_logs_ip_address')->nullable();
|
||||
$table->string('activity_logs_user_agent')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('activity_logs_user_id');
|
||||
$table->index('activity_logs_bus_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Capsule::schema()->dropIfExists('activity_logs');
|
||||
Capsule::schema()->dropIfExists('role_permissions');
|
||||
Capsule::schema()->dropIfExists('user_permissions');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateAuthAttemptsTable
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('auth_attempts')) {
|
||||
Capsule::schema()->create('auth_attempts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('email')->nullable();
|
||||
$table->string('ip')->index();
|
||||
$table->string('action')->index();
|
||||
$table->boolean('success')->default(false);
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Capsule::schema()->dropIfExists('auth_attempts');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use App\Models\Module;
|
||||
use Modules\Company\Models\Company;
|
||||
|
||||
class InsertAuthModule
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$moduleData = [
|
||||
'modules_name' => 'auth',
|
||||
'modules_display_name' => 'Authentication',
|
||||
'modules_description' => 'Authentication and authorization module for user management',
|
||||
'modules_version' => '1.0.0',
|
||||
'modules_author' => 'SysCMS Team',
|
||||
'modules_ative' => true,
|
||||
'modules_public' => true,
|
||||
'modules_blocked' => true, // Core module, cannot be disabled easily
|
||||
'modules_dependencies' => [],
|
||||
'modules_permissions' => [
|
||||
"auth.login",
|
||||
"auth.logout",
|
||||
"auth.register",
|
||||
"auth.profile",
|
||||
"auth.password.reset",
|
||||
"auth.password.change"
|
||||
],
|
||||
'modules_settings' => [
|
||||
"allow_registration" => true,
|
||||
"require_email_verification" => false,
|
||||
"password_min_length" => 8,
|
||||
"session_timeout" => 120
|
||||
],
|
||||
'modules_path' => 'modules/auth',
|
||||
'modules_namespace' => 'Modules\\Auth',
|
||||
'modules_icon' => 'bi bi-person-check',
|
||||
'menu_side_bar' => true,
|
||||
'menu_nav_bar' => true,
|
||||
'modules_order' => 1,
|
||||
'modules_install_date' => date('Y-m-d H:i:s'),
|
||||
'modules_update_date' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
// Check if module already exists
|
||||
$existingModule = Module::where('modules_name', 'auth')->first();
|
||||
|
||||
if (!$existingModule) {
|
||||
$module = Module::create($moduleData);
|
||||
|
||||
// Associate with all existing companies (bus_modules)
|
||||
// Assuming Company model and table exist.
|
||||
if (Capsule::schema()->hasTable('bus')) {
|
||||
$companies = Company::all();
|
||||
foreach ($companies as $company) {
|
||||
$exists = Capsule::table('bus_modules')
|
||||
->where('bus_modules_bus_id', $company->bus_id)
|
||||
->where('bus_modules_module_id', $module->modules_id)
|
||||
->exists();
|
||||
|
||||
if (!$exists) {
|
||||
Capsule::table('bus_modules')->insert([
|
||||
'bus_modules_bus_id' => $company->bus_id,
|
||||
'bus_modules_module_id' => $module->modules_id,
|
||||
'bus_modules_is_enabled' => true,
|
||||
'bus_modules_settings' => json_encode([]),
|
||||
'bus_modules_enabled_by' => 1,
|
||||
'bus_modules_enabled_at' => date('Y-m-d H:i:s'),
|
||||
'bus_modules_show_public_nav' => true,
|
||||
'bus_modules_show_dashboard_nav' => true,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$module = Module::where('modules_name', 'auth')->first();
|
||||
if ($module) {
|
||||
Capsule::table('bus_modules')->where('bus_modules_module_id', $module->modules_id)->delete();
|
||||
$module->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user