3
3
namespace Adldap \Laravel \Auth ;
4
4
5
5
use Adldap \Models \User ;
6
+ use Adldap \Laravel \Facades \Resolver ;
7
+ use Adldap \Laravel \Commands \Import ;
8
+ use Adldap \Laravel \Commands \SyncPassword ;
9
+ use Adldap \Laravel \Events \DiscoveredWithCredentials ;
10
+ use Adldap \Laravel \Events \AuthenticatedWithCredentials ;
11
+ use Illuminate \Support \Facades \Bus ;
12
+ use Illuminate \Support \Facades \Event ;
6
13
use Illuminate \Auth \EloquentUserProvider ;
7
14
use Illuminate \Contracts \Hashing \Hasher ;
8
15
use Illuminate \Contracts \Auth \UserProvider ;
@@ -87,17 +94,18 @@ public function updateRememberToken(Authenticatable $user, $token)
87
94
public function retrieveByCredentials (array $ credentials )
88
95
{
89
96
// Retrieve the LDAP user who is authenticating.
90
- $ user = $ this -> getResolver ()-> byCredentials ($ credentials );
97
+ $ user = Resolver:: byCredentials ($ credentials );
91
98
92
99
if ($ user instanceof User) {
93
100
// Set the currently authenticating LDAP user.
94
101
$ this ->user = $ user ;
95
102
96
- $ this -> handleDiscoveredWithCredentials ( $ user );
103
+ Event:: fire ( new DiscoveredWithCredentials ( $ user) );
97
104
98
105
// Import / locate the local user account.
99
- return $ this ->getImporter ()
100
- ->run ($ user , $ this ->createModel (), $ credentials );
106
+ return Bus::dispatch (
107
+ new Import ($ user , $ this ->createModel (), $ credentials )
108
+ );
101
109
}
102
110
103
111
if ($ this ->isFallingBack ()) {
@@ -114,14 +122,17 @@ public function validateCredentials(Authenticatable $model, array $credentials)
114
122
// they pass authentication before going further.
115
123
if (
116
124
$ this ->user instanceof User &&
117
- $ this -> getResolver ()-> authenticate ($ this ->user , $ credentials )
125
+ Resolver:: authenticate ($ this ->user , $ credentials )
118
126
) {
119
- $ this -> handleAuthenticatedWithCredentials ( $ this ->user , $ model );
127
+ Event:: fire ( new AuthenticatedWithCredentials ( $ this ->user , $ model) );
120
128
121
129
// Here we will perform authorization on the LDAP user. If all
122
130
// validation rules pass, we will allow the authentication
123
131
// attempt. Otherwise, it is automatically rejected.
124
- if ($ this ->passesValidation ($ model )) {
132
+ if ($ this ->passesValidation ($ this ->user , $ model )) {
133
+ // Sync / set the users password since it has been verified.
134
+ Bus::dispatch (new SyncPassword ($ model , $ credentials ));
135
+
125
136
// All of our validation rules have passed and we can
126
137
// finally save the model in case of changes.
127
138
$ model ->save ();
@@ -176,19 +187,6 @@ public function __call($name, $arguments)
176
187
return call_user_func_array ([$ this ->fallback , $ name ], $ arguments );
177
188
}
178
189
179
- /**
180
- * Determines if the model passes validation.
181
- *
182
- * @param Authenticatable $model
183
- *
184
- * @return bool
185
- */
186
- protected function passesValidation (Authenticatable $ model )
187
- {
188
- return $ this ->newValidator ($ this ->getRules ($ this ->user , $ model ))
189
- ->passes ();
190
- }
191
-
192
190
/**
193
191
* Determines if login fallback is enabled.
194
192
*
0 commit comments