Add users, teams, authentication, profile/login/register/navbar views

This commit is contained in:
Andras Bacsai
2023-03-24 14:54:17 +01:00
parent 436d22e385
commit e47d493776
36 changed files with 1106 additions and 66 deletions

View File

@@ -13,6 +13,8 @@ return new class extends Migration
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->boolean('is_root_user')->default(false);
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();

View File

@@ -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

@@ -16,6 +16,7 @@ return new class extends Migration
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->string('team_id');
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();

View File

@@ -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('teams', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('name');
$table->boolean('personal_team')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('teams');
}
};

View File

@@ -0,0 +1,32 @@
<?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('team_user', function (Blueprint $table) {
$table->id();
$table->foreignId('team_id');
$table->foreignId('user_id');
$table->string('role')->nullable();
$table->timestamps();
$table->unique(['team_id', 'user_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('team_user');
}
};

View File

@@ -2,21 +2,17 @@
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
// \App\Models\User::factory(10)->create();
// \App\Models\User::factory()->create([
// 'name' => 'Test User',
// 'email' => 'test@example.com',
// ]);
if (env('APP_ENV') === 'local') {
$this->call([
UserSeeder::class,
TeamSeeder::class,
]);
}
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Database\Seeders;
use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class TeamSeeder extends Seeder
{
public function run(): void
{
$root_user = User::find(1);
$normal_user = User::find(2);
$root_user_personal_team = Team::create([
'name' => "Root Team",
'personal_team' => true,
]);
$root_user_other_team = Team::create([
'name' => "Root User's Other Team",
'personal_team' => false,
]);
$normal_user_personal_team = Team::create([
'name' => 'Normal Team',
'personal_team' => true,
]);
DB::table('team_user')->insert([
'team_id' => $root_user_personal_team->id,
'user_id' => $root_user->id,
'role' => 'admin',
]);
DB::table('team_user')->insert([
'team_id' => $root_user_other_team->id,
'user_id' => $root_user->id,
'role' => 'admin',
]);
DB::table('team_user')->insert([
'team_id' => $normal_user_personal_team->id,
'user_id' => $normal_user->id,
'role' => 'admin',
]);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Database\Seeders;
use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UserSeeder extends Seeder
{
public function run(): void
{
User::factory()->create([
'id' => 1,
'name' => 'Root User',
'email' => 'test@example.com',
'is_root_user' => true,
]);
User::factory()->create([
'id' => 2,
'name' => 'Normal User',
'email' => 'test2@example.com',
]);
}
}