TRF Certest first commit

This commit is contained in:
2025-02-26 08:57:46 +01:00
commit 3ce064a108
2524 changed files with 475404 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.sqlite
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Vanguard\Country;
class CountryFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Country::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'country_code' => $this->faker->countryCode,
'iso_3166_2' => strtoupper($this->faker->randomLetter.$this->faker->randomLetter),
'iso_3166_3' => $this->faker->countryISOAlpha3,
'name' => $this->faker->country,
'region_code' => 123,
'sub_region_code' => 123,
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class PermissionFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = \Vanguard\Permission::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => Str::random(5),
'display_name' => implode(' ', $this->faker->words(2)),
'description' => substr($this->faker->paragraph, 0, 191),
'removable' => true,
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class RoleFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = \Vanguard\Role::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => Str::random(5),
'display_name' => implode(' ', $this->faker->words(2)),
'description' => $this->faker->sentence,
'removable' => true,
];
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Vanguard\Role;
use Vanguard\User;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'email' => $this->faker->email,
'password' => '$2y$10$A2A/2IIP.jsLzIiAPr.enuzxzRWzIzLWifqNU33PWPBGx6mkJFz72', // 123123123
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'phone' => $this->faker->phoneNumber,
'avatar' => null,
'address' => $this->faker->address,
'country_id' => function () {
return $this->faker->randomElement(\Vanguard\Country::pluck('id')->toArray());
},
'role_id' => function () {
return Role::factory()->create()->id;
},
'status' => \Vanguard\Support\Enum\UserStatus::ACTIVE,
'birthday' => $this->faker->date(),
'email_verified_at' => (string) now(),
];
}
}
View File
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('password_resets');
}
}
@@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class SetupCountriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Creates the users table
Schema::create('countries', function (Blueprint $table) {
$table->increments('id');
$table->string('capital', 255)->nullable();
$table->string('citizenship', 255)->nullable();
$table->string('country_code', 3)->default('');
$table->string('currency', 255)->nullable();
$table->string('currency_code', 255)->nullable();
$table->string('currency_sub_unit', 255)->nullable();
$table->string('currency_symbol', 3)->nullable();
$table->string('full_name', 255)->nullable();
$table->string('iso_3166_2', 2)->default('');
$table->string('iso_3166_3', 3)->default('');
$table->string('name', 255)->default('');
$table->string('region_code', 3)->default('');
$table->string('sub_region_code', 3)->default('');
$table->boolean('eea')->default(0);
$table->string('calling_code', 3)->nullable();
$table->string('flag', 6)->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('countries');
}
}
@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('username')->nullable()->index();
$table->string('password');
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('phone')->nullable();
$table->string('avatar')->nullable();
$table->string('address')->nullable();
$table->unsignedInteger('country_id')->nullable();
$table->unsignedInteger('role_id');
$table->date('birthday')->nullable();
$table->timestamp('last_login')->nullable();
$table->string('status', 20)->index();
$table->integer('two_factor_country_code')->nullable();
$table->bigInteger('two_factor_phone', false, true)->nullable();
$table->text('two_factor_options')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->rememberToken();
$table->timestamps();
$table->index('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSocialLoginTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('social_logins', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->string('provider', 50);
$table->string('provider_id');
$table->string('avatar');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('social_logins');
}
}
@@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class SetupAuthorizationTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Create table for storing roles
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('display_name')->nullable();
$table->string('description')->nullable();
$table->boolean('removable')->default(true);
$table->timestamps();
});
// Create table for storing permissions
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('display_name')->nullable();
$table->string('description')->nullable();
$table->boolean('removable')->default(true);
$table->timestamps();
});
// Create table for associating permissions to roles (Many-to-Many)
Schema::create('permission_role', function (Blueprint $table) {
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('permission_id')->references('id')->on('permissions')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['permission_id', 'role_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('permission_role');
Schema::drop('permissions');
Schema::drop('roles');
}
}
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSessionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->unique();
$table->integer('user_id')->nullable();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->text('payload');
$table->integer('last_activity');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('sessions');
}
}
@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateUserActivityTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_activity', function (Blueprint $table) {
$table->increments('id');
$table->text('description');
$table->unsignedInteger('user_id');
$table->string('ip_address', 45);
$table->text('user_agent');
$table->timestamp('created_at')->nullable();
});
Schema::table('user_activity', function (Blueprint $table) {
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (DB::getDriverName() != 'sqlite') {
Schema::table('user_activity', function (Blueprint $table) {
$table->dropForeign('user_activity_user_id_foreign');
});
}
Schema::drop('user_activity');
\DB::table('permissions')->where('name', 'users.activity')->delete();
}
}
@@ -0,0 +1,52 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddForeignKeys extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->foreign('country_id')
->references('id')
->on('countries')
->onDelete('set null');
$table->foreign('role_id')
->references('id')
->on('roles');
});
Schema::table('social_logins', function (Blueprint $table) {
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (DB::getDriverName() != 'sqlite') {
Schema::table('users', function (Blueprint $table) {
$table->dropForeign('users_country_id_foreign');
$table->dropForeign('users_role_id_foreign');
});
Schema::table('social_logins', function (Blueprint $table) {
$table->dropForeign('social_logins_user_id_foreign');
});
}
}
}
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSettingsTable extends Migration
{
/**
* Set up the options.
*/
public function __construct()
{
$this->table = config('setting.database.table');
$this->key = config('setting.database.key');
$this->value = config('setting.database.value');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create($this->table, function (Blueprint $table) {
$table->increments('id');
$table->string($this->key)->index();
$table->text($this->value);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop($this->table);
}
}
@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAnnouncementsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('announcements', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('user_id');
$table->string('title');
$table->text('body');
$table->timestamps();
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
});
Schema::table('users', function (Blueprint $table) {
$table->timestamp('announcements_last_read_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('announcements_last_read_at');
});
Schema::table('announcements', function (Blueprint $table) {
$table->dropForeign('announcements_user_id_foreign');
});
Schema::dropIfExists('announcements');
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePersonalAccessTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->bigIncrements('id');
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('personal_access_tokens');
}
}
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('personal_access_tokens', function (Blueprint $table) {
$table->timestamp('expires_at')->nullable()->after('last_used_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
};
@@ -0,0 +1,46 @@
\<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravel\Fortify\Fortify;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->text('two_factor_secret')
->after('password')
->nullable();
$table->text('two_factor_recovery_codes')
->after('two_factor_secret')
->nullable();
if (Fortify::confirmsTwoFactorAuthentication()) {
$table->timestamp('two_factor_confirmed_at')
->after('two_factor_recovery_codes')
->nullable();
}
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(array_merge([
'two_factor_secret',
'two_factor_recovery_codes',
], Fortify::confirmsTwoFactorAuthentication() ? [
'two_factor_confirmed_at',
] : []));
});
}
};
View File
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class CountriesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//Get all of the countries
$countries = \Countries::getList();
foreach ($countries as $countryId => $country) {
\DB::table('countries')->insert([
'id' => $countryId,
'capital' => ((isset($country['capital'])) ? $country['capital'] : null),
'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
'country_code' => $country['country-code'],
'currency' => ((isset($country['currency'])) ? $country['currency'] : null),
'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null),
'iso_3166_2' => $country['iso_3166_2'],
'iso_3166_3' => $country['iso_3166_3'],
'name' => $country['name'],
'region_code' => $country['region-code'],
'sub_region_code' => $country['sub-region-code'],
'eea' => (bool) $country['eea'],
'calling_code' => $country['calling_code'],
'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null),
'flag' => ((isset($country['flag'])) ? $country['flag'] : null),
]);
}
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call(\Database\Seeders\CountriesSeeder::class);
$this->call(\Database\Seeders\RolesSeeder::class);
$this->call(\Database\Seeders\PermissionsSeeder::class);
$this->call(\Database\Seeders\UserSeeder::class);
Model::reguard();
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Vanguard\Permission;
use Vanguard\Role;
class PermissionsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$adminRole = Role::where('name', 'Admin')->first();
$permissions[] = Permission::create([
'name' => 'users.manage',
'display_name' => 'Manage Users',
'description' => 'Manage users and their sessions.',
'removable' => false,
]);
$permissions[] = Permission::create([
'name' => 'users.activity',
'display_name' => 'View System Activity Log',
'description' => 'View activity log for all system users.',
'removable' => false,
]);
$permissions[] = Permission::create([
'name' => 'roles.manage',
'display_name' => 'Manage Roles',
'description' => 'Manage system roles.',
'removable' => false,
]);
$permissions[] = Permission::create([
'name' => 'permissions.manage',
'display_name' => 'Manage Permissions',
'description' => 'Manage role permissions.',
'removable' => false,
]);
$permissions[] = Permission::create([
'name' => 'settings.general',
'display_name' => 'Update General System Settings',
'description' => '',
'removable' => false,
]);
$permissions[] = Permission::create([
'name' => 'settings.auth',
'display_name' => 'Update Authentication Settings',
'description' => 'Update authentication and registration system settings.',
'removable' => false,
]);
$permissions[] = Permission::create([
'name' => 'settings.notifications',
'display_name' => 'Update Notifications Settings',
'description' => '',
'removable' => false,
]);
$adminRole->attachPermissions($permissions);
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Vanguard\Role;
class RolesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Role::create([
'name' => 'Admin',
'display_name' => 'Admin',
'description' => 'System administrator.',
'removable' => false,
]);
Role::create([
'name' => 'User',
'display_name' => 'User',
'description' => 'Default system user.',
'removable' => false,
]);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Vanguard\Role;
use Vanguard\Support\Enum\UserStatus;
use Vanguard\User;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$admin = Role::where('name', 'Admin')->first();
User::create([
'first_name' => 'Vanguard',
'email' => 'admin@example.com',
'username' => 'admin',
'password' => 'admin123',
'avatar' => null,
'country_id' => null,
'role_id' => $admin->id,
'status' => UserStatus::ACTIVE,
'email_verified_at' => now(),
]);
}
}