Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 5a48b5a

Browse files
committed
Added event for handling soft-deleted users during authentication
- Closes #184
1 parent 9abc2dd commit 5a48b5a

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/AdldapAuthUserProvider.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Adldap\Laravel;
44

5+
use Adldap\Laravel\Events\AuthenticatedModelTrashed;
56
use Adldap\Models\User;
67
use Adldap\Laravel\Traits\ImportsUsers;
78
use Adldap\Laravel\Events\DiscoveredWithCredentials;
@@ -57,7 +58,11 @@ public function retrieveByCredentials(array $credentials)
5758
$model = $this->getModelFromAdldap($user, $password);
5859

5960
if (method_exists($model, 'trashed') && $model->trashed()) {
60-
// We won't allow deleted users to authenticate.
61+
// If the model is soft-deleted, we'll fire an event
62+
// with the affected LDAP user and their model.
63+
$this->handleAuthenticatedModelTrashed($user, $model);
64+
65+
// We also won't allow soft-deleted users to authenticate.
6166
return;
6267
}
6368

@@ -109,6 +114,17 @@ protected function handleAuthenticatedWithCredentials(User $user, $model)
109114
Event::fire(new AuthenticatedWithCredentials($user, $model));
110115
}
111116

117+
/**
118+
* Handle an authenticated users model that has been soft deleted.
119+
*
120+
* @param \Adldap\Models\User $user
121+
* @param Authenticatable $model
122+
*/
123+
protected function handleAuthenticatedModelTrashed(User $user, $model)
124+
{
125+
Event::fire(new AuthenticatedModelTrashed($user, $model));
126+
}
127+
112128
/**
113129
* Handle discovered LDAP users before they are authenticated.
114130
*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Adldap\Laravel\Events;
4+
5+
use Adldap\Models\User;
6+
use Illuminate\Contracts\Auth\Authenticatable;
7+
8+
class AuthenticatedModelTrashed
9+
{
10+
/**
11+
* The authenticated LDAP user.
12+
*
13+
* @var User
14+
*/
15+
public $user;
16+
17+
/**
18+
* The authenticated LDAP users model.
19+
*
20+
* @var Authenticatable
21+
*/
22+
public $model;
23+
24+
/**
25+
* Constructor.
26+
*
27+
* @param User $user
28+
* @param Authenticatable $model
29+
*/
30+
public function __construct(User $user, Authenticatable $model)
31+
{
32+
$this->user = $user;
33+
$this->model = $model;
34+
}
35+
}

0 commit comments

Comments
 (0)