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

Commit 4421640

Browse files
committed
Use Event facade for dispatching events
1 parent 7170b30 commit 4421640

File tree

6 files changed

+23
-17
lines changed

6 files changed

+23
-17
lines changed

src/Auth/DatabaseUserProvider.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Adldap\Laravel\Events\DiscoveredWithCredentials;
1414
use Adldap\Laravel\Events\AuthenticatedWithCredentials;
1515
use Illuminate\Support\Facades\Bus;
16+
use Illuminate\Support\Facades\Event;
1617
use Illuminate\Support\Facades\Config;
1718
use Illuminate\Auth\EloquentUserProvider;
1819
use Illuminate\Contracts\Auth\Authenticatable;
@@ -40,7 +41,7 @@ public function retrieveByCredentials(array $credentials)
4041
// Set the currently authenticating LDAP user.
4142
$this->user = $user;
4243

43-
event(new DiscoveredWithCredentials($user));
44+
Event::dispatch(new DiscoveredWithCredentials($user));
4445

4546
// Import / locate the local user account.
4647
return Bus::dispatch(
@@ -62,7 +63,7 @@ public function validateCredentials(Authenticatable $model, array $credentials)
6263
// If an LDAP user was discovered, we can go
6364
// ahead and try to authenticate them.
6465
if (Resolver::authenticate($this->user, $credentials)) {
65-
event(new AuthenticatedWithCredentials($this->user, $model));
66+
Event::dispatch(new AuthenticatedWithCredentials($this->user, $model));
6667

6768
// Here we will perform authorization on the LDAP user. If all
6869
// validation rules pass, we will allow the authentication
@@ -78,15 +79,15 @@ public function validateCredentials(Authenticatable $model, array $credentials)
7879
if ($model->wasRecentlyCreated) {
7980
// If the model was recently created, they
8081
// have been imported successfully.
81-
event(new Imported($this->user, $model));
82+
Event::dispatch(new Imported($this->user, $model));
8283
}
8384

84-
event(new AuthenticationSuccessful($this->user, $model));
85+
Event::dispatch(new AuthenticationSuccessful($this->user, $model));
8586

8687
return true;
8788
}
8889

89-
event(new AuthenticationRejected($this->user, $model));
90+
Event::dispatch(new AuthenticationRejected($this->user, $model));
9091
}
9192

9293
// LDAP Authentication failed.

src/Auth/NoDatabaseUserProvider.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Adldap\Laravel\Events\AuthenticationSuccessful;
99
use Adldap\Laravel\Events\DiscoveredWithCredentials;
1010
use Adldap\Laravel\Events\AuthenticatedWithCredentials;
11+
use Illuminate\Support\Facades\Event;
1112
use Illuminate\Contracts\Auth\UserProvider;
1213
use Illuminate\Contracts\Auth\Authenticatable;
1314

@@ -49,7 +50,7 @@ public function updateRememberToken(Authenticatable $user, $token)
4950
public function retrieveByCredentials(array $credentials)
5051
{
5152
if ($user = Resolver::byCredentials($credentials)) {
52-
event(new DiscoveredWithCredentials($user));
53+
Event::dispatch(new DiscoveredWithCredentials($user));
5354

5455
return $user;
5556
}
@@ -61,15 +62,15 @@ public function retrieveByCredentials(array $credentials)
6162
public function validateCredentials(Authenticatable $user, array $credentials)
6263
{
6364
if (Resolver::authenticate($user, $credentials)) {
64-
event(new AuthenticatedWithCredentials($user));
65+
Event::dispatch(new AuthenticatedWithCredentials($user));
6566

6667
if ($this->passesValidation($user)) {
67-
event(new AuthenticationSuccessful($user));
68+
Event::dispatch(new AuthenticationSuccessful($user));
6869

6970
return true;
7071
}
7172

72-
event(new AuthenticationRejected($user));
73+
Event::dispatch(new AuthenticationRejected($user));
7374
}
7475

7576
return false;

src/Commands/Import.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Adldap\Laravel\Events\Importing;
88
use Adldap\Laravel\Events\Synchronized;
99
use Adldap\Laravel\Events\Synchronizing;
10+
use Illuminate\Support\Facades\Event;
1011
use Illuminate\Support\Facades\Config;
1112
use Illuminate\Database\Eloquent\Model;
1213

@@ -51,14 +52,14 @@ public function handle()
5152
$model = $this->findUser() ?: $this->model->newInstance();
5253

5354
if (! $model->exists) {
54-
event(new Importing($this->user, $model));
55+
Event::dispatch(new Importing($this->user, $model));
5556
}
5657

57-
event(new Synchronizing($this->user, $model));
58+
Event::dispatch(new Synchronizing($this->user, $model));
5859

5960
$this->sync($model);
6061

61-
event(new Synchronized($this->user, $model));
62+
Event::dispatch(new Synchronized($this->user, $model));
6263

6364
return $model;
6465
}

src/Middleware/WindowsAuthenticate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Http\Request;
1414
use Illuminate\Contracts\Auth\Guard;
1515
use Illuminate\Support\Facades\Bus;
16+
use Illuminate\Support\Facades\Event;
1617
use Illuminate\Support\Facades\Config;
1718

1819
class WindowsAuthenticate
@@ -109,7 +110,7 @@ protected function retrieveAuthenticatedUser($username)
109110
*/
110111
protected function fireAuthenticatedEvent(User $user, $model = null)
111112
{
112-
event(new AuthenticatedWithWindows($user, $model));
113+
Event::dispatch(new AuthenticatedWithWindows($user, $model));
113114
}
114115

115116
/**

src/Resolvers/UserResolver.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Adldap\Laravel\Events\AuthenticationFailed;
1313
use Adldap\Laravel\Auth\NoDatabaseUserProvider;
1414
use Illuminate\Support\Facades\Auth;
15+
use Illuminate\Support\Facades\Event;
1516
use Illuminate\Support\Facades\Config;
1617
use Illuminate\Contracts\Auth\UserProvider;
1718
use Illuminate\Contracts\Auth\Authenticatable;
@@ -112,15 +113,15 @@ public function authenticate(User $user, array $credentials = [])
112113

113114
$password = $this->getPasswordFromCredentials($credentials);
114115

115-
event(new Authenticating($user, $username));
116+
Event::dispatch(new Authenticating($user, $username));
116117

117118
if ($this->getLdapAuthProvider()->auth()->attempt($username, $password)) {
118-
event(new Authenticated($user));
119+
Event::dispatch(new Authenticated($user));
119120

120121
return true;
121122
}
122123

123-
event(new AuthenticationFailed($user));
124+
Event::dispatch(new AuthenticationFailed($user));
124125

125126
return false;
126127
}

src/Validation/Rules/DenyTrashed.php

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

33
namespace Adldap\Laravel\Validation\Rules;
44

5+
use Illuminate\Support\Facades\Event;
56
use Adldap\Laravel\Events\AuthenticatedModelTrashed;
67

78
class DenyTrashed extends Rule
@@ -12,7 +13,7 @@ class DenyTrashed extends Rule
1213
public function isValid()
1314
{
1415
if ($this->isTrashed()) {
15-
event(
16+
Event::dispatch(
1617
new AuthenticatedModelTrashed($this->user, $this->model)
1718
);
1819

0 commit comments

Comments
 (0)