Skip to content

Auth #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ SUPPORT_EMAIL=

FRONTEND_URL=

CLOUDFLARE_R2_ACCESS_KEY_ID=
CLOUDFLARE_R2_SECRET_ACCESS_KEY=
CLOUDFLARE_R2_BUCKET=
CLOUDFLARE_R2_ENDPOINT=
CLOUDFLARE_R2_URL=

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
"require": {
"php": "^8.2",
"ext-fileinfo": "*",
"ext-http": "*",
"darkaonline/l5-swagger": "^8.6",
"laravel/breeze": "^2.1",
"laravel/framework": "^11.9",
"laravel/sanctum": "^4.0",
"laravel/socialite": "^5.15",
"laravel/tinker": "^2.9",
"larowka/prevent-duplicate-requests": "^1.1"
"larowka/prevent-duplicate-requests": "^1.1",
"league/flysystem": "^3.0",
"league/flysystem-aws-s3-v3": "^3.0"
},
"require-dev": {
"fakerphp/faker": "^1.23",
Expand Down
20 changes: 20 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@
'throw' => false,
],

'uploads' => [
'driver' => 'local',
'root' => storage_path('app/public/uploads'),
'url' => env('APP_URL').'/storage/uploads',
'visibility' => 'public',
],

'r2' => [
'driver' => 's3',
'key' => env('CLOUDFLARE_R2_ACCESS_KEY_ID'),
'secret' => env('CLOUDFLARE_R2_SECRET_ACCESS_KEY'),
'region' => 'auto',
'bucket' => env('CLOUDFLARE_R2_BUCKET'),
'url' => env('CLOUDFLARE_R2_URL'),
'visibility' => 'private',
'endpoint' => env('CLOUDFLARE_R2_ENDPOINT'),
'use_path_style_endpoint' => env('CLOUDFLARE_R2_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],

],

/*
Expand Down
7 changes: 6 additions & 1 deletion database/migrations/0001_01_01_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ public function up(): void
Schema::create('roles', function (Blueprint $table): void {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->bigInteger('created_at')->useCurrent();
$table->bigInteger('updated_at')->useCurrent();
});

Schema::create('users', function (Blueprint $table): void {
$table->uuid('id')->primary();
$table->string('name');
$table->string('first_name');
$table->string('last_name');
$table->string('avatar')->nullable();
$table->string('phone')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
Expand Down
43 changes: 43 additions & 0 deletions database/migrations/2023_01_01_000000_create_admins_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{

Schema::create('system_users', function (Blueprint $table): void {
$table->uuid('id')->primary();
$table->string('first_name');
$table->string('last_name');
$table->string('avatar')->nullable();
$table->string('phone')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password')->nullable();
$table->text('verification_token')->nullable();
$table->boolean('super_admin')->default(false);
$table->dateTime('verification_token_expiry')->nullable();
$table->rememberToken();
$table->string('status')->default('PENDING');
$table->bigInteger('created_at')->useCurrent();
$table->bigInteger('updated_at')->useCurrent();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('system_users');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ public function up(): void
$table->uuidMorphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->string('refresh_token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamp('refresh_token_expires_at');
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notifications', function (Blueprint $table): void {
$table->uuid('id')->primary();
$table->string('type');
$table->uuidMorphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notifications');
}
};
31 changes: 31 additions & 0 deletions database/migrations/2025_02_23_153233_create_permissions_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->bigInteger('created_at')->useCurrent();
$table->bigInteger('updated_at')->useCurrent();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('permissions');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('permission_role', function (Blueprint $table) {
$table->id();
$table->foreignId('permission_id')->constrained()->onDelete('cascade');
$table->foreignId('role_id')->constrained()->onDelete('cascade');
$table->bigInteger('created_at')->useCurrent();
$table->bigInteger('updated_at')->useCurrent();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('permission_role');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('admin_activity_logs', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('admin_id')->references('id')->on('system_users')->cascadeOnDelete();
$table->string('action');
$table->string('model_type')->nullable(); // e.g., User, Contract
$table->uuid('model_id')->nullable();
$table->json('meta')->nullable(); // Extra metadata
$table->bigInteger('created_at')->useCurrent();
$table->bigInteger('updated_at')->useCurrent();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('admin_activity_logs');
}
};
35 changes: 35 additions & 0 deletions database/seeders/AdminSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Modules\V1\User\Models\Admin;
use Shared\Enums\StatusEnum;
use Shared\Helpers\DateTimeHelper;

class AdminSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::transaction(function () {
$timestamp = DateTimeHelper::timestamp();

Admin::firstOrCreate([
'first_name' => 'Super',
'last_name' => 'Admin',
'email' => 'admin@gmail.com',
'password' => Hash::make('password'),
'email_verified_at' => now(),
'status' => StatusEnum::ACTIVE,
'super_admin' => true,
'created_at' => $timestamp,
'updated_at' => $timestamp,
]);
});
}
}
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Database\Seeders;
Expand Down
57 changes: 57 additions & 0 deletions database/seeders/PermissionSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Modules\V1\User\Models\Permission;

class PermissionSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Define permission groups
$permissions = [
'user_management' => [
'view users',
'create users',
'edit users',
'delete users',
],
'role_management' => [
'view roles',
'create roles',
'edit roles',
'delete roles',
],
'permission_management' => [
'view permissions',
'assign permissions',
],
'creator_management' => [
'view creators',
'approve creators',
'suspend creators',
],
'content_management' => [
'view content',
'approve content',
'delete content',
],
];

// Seed permissions
foreach ($permissions as $group => $perms) {
foreach ($perms as $perm) {
Permission::firstOrCreate([
'name' => $perm,
'slug' => Str::slug($perm),
]);
}
}
}
}
3 changes: 2 additions & 1 deletion database/seeders/RoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Modules\V1\User\Enums\RoleEnum;
use Modules\V1\User\Models\Role;

Expand All @@ -17,7 +18,7 @@ public function run(): void
{
$roles = RoleEnum::names();
foreach ($roles as $role) {
Role::firstOrCreate(['name' => $role]);
Role::firstOrCreate(['name' => $role, 'slug' => Str::slug($role)]);
}
}
}
13 changes: 13 additions & 0 deletions routes/v1/admin/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Route;
use Modules\V1\Admin\Controllers\AdminController;

Route::prefix('admins')->as('admins:')->group(function (): void {
Route::get('', [AdminController::class, 'index'])->name('index');
Route::post('', [AdminController::class, 'store'])->name('store');
Route::patch('{admin}', [AdminController::class, 'update'])->name('update');
Route::patch('{admin}/change-role', [AdminController::class, 'changeRole'])->name('changeRole');
});
Loading