Skip to content

Commit

Permalink
fix registration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshKisb committed Sep 6, 2024
1 parent 168834f commit 5dc4256
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 30 deletions.
21 changes: 3 additions & 18 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function create(array $input): User
Rule::unique(User::class),
],
'password' => $this->passwordRules(),
'role' => ['required', 'string', Rule::in(['tenant', 'buyer', 'seller', 'landlord', 'contractor'])],
// 'role' => ['required', 'string', Rule::in(['tenant', 'buyer', 'seller', 'landlord', 'contractor'])],
])->validate();


Expand All @@ -49,25 +49,10 @@ public function create(array $input): User
$team = $this->assignOrCreateTeam($user);
$user->switchTeam($team);
setPermissionsTeamId($team->id);
$user->assignRole($input['role']);
$user->assignRole('free');
});
});
// $user = DB::transaction(function () use ($input) {
// return tap(,
// , function (User $user) use ($input) {
// $team = $this->assignOrCreateTeam($user);
// $user->switchTeam($team);
// setPermissionsTeamId($team->id);
// $user->assignRole($input['role']);
// });
// });

Log::info('User created successfully', [
'user_id' => $user->id,
'email' => $user->email,
'role' => $input['role'],
]);


return $user;
} catch (\Illuminate\Validation\ValidationException $e) {
Log::error('User creation validation failed', [
Expand Down
24 changes: 15 additions & 9 deletions app/Models/Content.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<?php

namespace App\Models;

use App\Services\FileService;
use App\Traits\SEOable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

class Content extends Model
Expand Down Expand Up @@ -34,24 +42,22 @@ public static function boot()
}
}
});

static::saved(function ($content) {
Cache::forget("content_{$content->id}");
});
}

public function author()
{
return $this->belongsTo(User::class, 'author_id');
}

public static function boot()
{
parent::boot();
static::saved(function ($content) {
Cache::forget("content_{$content->id}");
});
}

public static function findCached($id)
{
return Cache::remember("content_{$id}", now()->addHours(24), function () use ($id) {
return static::find($id);
});
}
}

}
49 changes: 46 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasDefaultTenant;
use Filament\Models\Contracts\HasTenants;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
Expand All @@ -11,15 +15,23 @@
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;
use Filament\Panel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Collection;
use JoelButcher\Socialstream\SetsProfilePhotoFromUrl;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
class User extends Authenticatable implements HasDefaultTenant, HasTenants, FilamentUser
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use HasTeams;
use HasProfilePhoto {
HasProfilePhoto::profilePhotoUrl as getPhotoUrl;
}
use Notifiable;
use SetsProfilePhotoFromUrl;
use HasTeams;
use TwoFactorAuthenticatable;
use HasRoles;

Expand Down Expand Up @@ -68,8 +80,39 @@ protected function casts(): array
];
}

public function getTenants(Panel $panel)
public function getTenants(Panel $panel): array | Collection
{
return $this->teams;
}

public function canAccessPanel(Panel $panel): bool
{
$user = auth()->user();
if ($panel->getId() === "admin" && !$user->hasRole('admin')) {
return false;
}

return true; // TODO: Check panel and role
}

public function canAccessTenant(Model $tenant): bool
{
return $this->teams->contains($tenant);
}

public function canAccessFilament(): bool
{
// return $this->hasVerifiedEmail();
return true;
}

public function getDefaultTenant(Panel $panel): ?Model
{
return $this->latestTeam;
}

public function latestTeam(): BelongsTo
{
return $this->belongsTo(Team::class, 'current_team_id');
}
}

0 comments on commit 5dc4256

Please sign in to comment.