Skip to content

Commit

Permalink
refactor: update user activation logic and restore guard registration…
Browse files Browse the repository at this point in the history
…s (v4)

Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jan 25, 2025
1 parent 3e9bf92 commit 0158842
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
17 changes: 17 additions & 0 deletions src/Auth/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Igniter\User\Auth;

use Igniter\Flame\Support\Facades\Igniter;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
Expand All @@ -20,6 +21,11 @@ class AuthServiceProvider extends ServiceProvider
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../../config/auth.php', 'igniter-auth');

$this->registerGuards();

AliasLoader::getInstance()->alias('Auth', \Igniter\User\Facades\Auth::class);
AliasLoader::getInstance()->alias('AdminAuth', \Igniter\User\Facades\AdminAuth::class);
}

/**
Expand Down Expand Up @@ -50,6 +56,17 @@ public function boot()
});
}

protected function registerGuards(): void
{
$this->app->singleton('main.auth', function() {
return resolve('auth')->guard(config('igniter-auth.guards.web', 'web'));
});

$this->app->singleton('admin.auth', function() {
return resolve('auth')->guard(config('igniter-auth.guards.admin', 'web'));
});
}

protected function configureAuthGuards()
{
Auth::resolved(function($auth) {
Expand Down
17 changes: 0 additions & 17 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Igniter\User\Subscribers\AssigneeUpdatedSubscriber;
use Igniter\User\Subscribers\ConsoleSubscriber;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Notifications\Events\NotificationSent;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\RateLimiter;
Expand Down Expand Up @@ -65,11 +64,6 @@ public function register()
$this->registerConsoleCommand('igniter.assignable.allocator', AllocatorCommand::class);
$this->registerConsoleCommand('igniter.user-state.clear', ClearUserStateCommand::class);

$this->registerGuards();

AliasLoader::getInstance()->alias('Auth', \Igniter\User\Facades\Auth::class);
AliasLoader::getInstance()->alias('AdminAuth', \Igniter\User\Facades\AdminAuth::class);

$this->registerBladeDirectives();
$this->registerSystemSettings();
$this->registerEventGlobalParams();
Expand Down Expand Up @@ -296,17 +290,6 @@ protected function registerBladeDirectives()
});
}

protected function registerGuards(): void
{
$this->app->singleton('main.auth', function() {
return resolve('auth')->guard(config('igniter-auth.guards.web', 'web'));
});

$this->app->singleton('admin.auth', function() {
return resolve('auth')->guard(config('igniter-auth.guards.admin', 'web'));
});
}

protected function registerUserPanelAndNotificationsAdminMenus()
{
if (!Igniter::runningInAdmin()) {
Expand Down
1 change: 1 addition & 0 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public function register(array $attributes, $activate = false)
$this->user_role_id = array_get($attributes, 'user_role_id');
$this->super_user = array_get($attributes, 'super_user', false);
$this->status = array_get($attributes, 'status', true);
$this->is_activated = $activate ? false : null; // Set to false to prevent auto activation in observer
$this->save();

if ($activate) {
Expand Down

0 comments on commit 0158842

Please sign in to comment.