-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
838 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use App\Notifications\Admin\WelcomeNotification as AdminWelcomeNotification; | ||
use App\Notifications\Organizations\WelcomeNotification; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Str; | ||
|
||
trait MustSetInitialPassword | ||
{ | ||
protected static function bootMustSetInitialPassword(): void | ||
{ | ||
static::creating(function (self $user) { | ||
if (! $user->password) { | ||
$user->password = Hash::make(Str::random(128)); | ||
} | ||
}); | ||
|
||
static::created(function (self $user) { | ||
$user->sendWelcomeNotification(); | ||
}); | ||
} | ||
|
||
public function hasSetPassword(): bool | ||
{ | ||
return ! \is_null($this->password_set_at); | ||
} | ||
|
||
public function setPassword(string $password): bool | ||
{ | ||
return $this->update([ | ||
'password' => Hash::make($password), | ||
'password_set_at' => $this->freshTimestamp(), | ||
]); | ||
} | ||
|
||
public function sendWelcomeNotification(): void | ||
{ | ||
$this->notify( | ||
$this->is_admin | ||
? new AdminWelcomeNotification | ||
: new WelcomeNotification | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
app/Filament/Admin/Resources/UserResource/Pages/CreateUser.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Admin\Resources\UserResource\Pages; | ||
|
||
use App\Filament\Admin\Resources\UserResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateUser extends CreateRecord | ||
{ | ||
protected static string $resource = UserResource::class; | ||
|
||
protected static bool $canCreateAnother = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Filament\Facades\Filament; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class UpdateDefaultTenant | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
$user = Filament::auth()->user(); | ||
$tenant = Filament::getTenant(); | ||
|
||
if ($user->latest_organization_id !== $tenant->id) { | ||
$user->update([ | ||
'latest_organization_id' => $tenant->id, | ||
]); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Responses; | ||
|
||
use Filament\Facades\Filament; | ||
use Filament\Http\Responses\Auth\Contracts\LoginResponse as Responsable; | ||
use Illuminate\Http\RedirectResponse; | ||
use Livewire\Features\SupportRedirects\Redirector; | ||
|
||
class LoginResponse implements Responsable | ||
{ | ||
public function toResponse($request): RedirectResponse | Redirector | ||
{ | ||
$user = Filament::auth()->user(); | ||
|
||
if ($user->is_admin) { | ||
$panel = Filament::getPanel('admin'); | ||
$parameters = []; | ||
} else { | ||
$panel = Filament::getPanel('organization'); | ||
$parameters = $user->getDefaultTenant($panel); | ||
} | ||
|
||
return redirect()->intended($panel->route('pages.dashboard', $parameters)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Listeners; | ||
|
||
use Illuminate\Auth\Events\Login; | ||
|
||
class LogSuccessfulLogin | ||
{ | ||
public function handle(Login $event): void | ||
{ | ||
activity('system') | ||
->by($event->user) | ||
->on($event->user) | ||
->withProperties([ | ||
'ip' => request()->ip(), | ||
'user_agent' => request()->userAgent(), | ||
]) | ||
->event('logged_in') | ||
->log('logged_in'); | ||
} | ||
} |
Oops, something went wrong.