3
3
namespace Adldap \Laravel ;
4
4
5
5
use Adldap \Laravel \Facades \Adldap ;
6
- use Adldap \Schemas \ActiveDirectory ;
7
6
use Adldap \Models \User ;
7
+ use Adldap \Schemas \ActiveDirectory ;
8
+ use Illuminate \Auth \EloquentUserProvider ;
9
+ use Illuminate \Contracts \Auth \Authenticatable ;
10
+ use Illuminate \Database \Eloquent \Model ;
8
11
use Illuminate \Support \Arr ;
9
12
use Illuminate \Support \Facades \Config ;
10
- use Illuminate \Database \Eloquent \Model ;
11
- use Illuminate \Contracts \Auth \Authenticatable ;
12
- use Illuminate \Auth \EloquentUserProvider ;
13
13
14
14
class AdldapAuthUserProvider extends EloquentUserProvider
15
15
{
16
16
/**
17
- * {@inheritDoc }
17
+ * {@inheritdoc }
18
18
*/
19
19
public function retrieveById ($ identifier )
20
20
{
@@ -24,7 +24,7 @@ public function retrieveById($identifier)
24
24
}
25
25
26
26
/**
27
- * {@inheritDoc }
27
+ * {@inheritdoc }
28
28
*/
29
29
public function retrieveByToken ($ identifier , $ token )
30
30
{
@@ -34,7 +34,7 @@ public function retrieveByToken($identifier, $token)
34
34
}
35
35
36
36
/**
37
- * {@inheritDoc }
37
+ * {@inheritdoc }
38
38
*/
39
39
public function retrieveByCredentials (array $ credentials )
40
40
{
@@ -54,30 +54,30 @@ public function retrieveByCredentials(array $credentials)
54
54
$ user = $ query ->first ();
55
55
56
56
// If the user is an Adldap User model instance.
57
- if ($ user instanceof User) {
57
+ if ($ user instanceof User) {
58
58
// Retrieve the users login attribute.
59
59
$ username = $ user ->{$ this ->getLoginAttribute ()};
60
60
61
- if (is_array ($ username )) {
61
+ if (is_array ($ username )) {
62
62
$ username = Arr::get ($ username , 0 );
63
63
}
64
64
65
65
// Get the password input array key.
66
66
$ key = $ this ->getPasswordKey ();
67
67
68
68
// Try to log the user in.
69
- if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
69
+ if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
70
70
// Login was successful, we'll create a new
71
71
// Laravel model with the Adldap user.
72
72
return $ this ->getModelFromAdldap ($ user , $ credentials [$ key ]);
73
73
}
74
74
}
75
75
76
- return null ;
76
+ return ;
77
77
}
78
78
79
79
/**
80
- * Creates a local User from Active Directory
80
+ * Creates a local User from Active Directory.
81
81
*
82
82
* @param User $user
83
83
* @param string $password
@@ -105,7 +105,9 @@ protected function getModelFromAdldap(User $user, $password)
105
105
$ model = $ this ->createModel ()->newQuery ()->where ([$ key => $ username ])->first ();
106
106
107
107
// Create the model instance of it isn't found.
108
- if (!$ model ) $ model = $ this ->createModel ();
108
+ if (!$ model ) {
109
+ $ model = $ this ->createModel ();
110
+ }
109
111
110
112
// Set the username and password in case
111
113
// of changes in active directory.
@@ -118,7 +120,7 @@ protected function getModelFromAdldap(User $user, $password)
118
120
// attributes on the model.
119
121
$ model = $ this ->syncModelFromAdldap ($ user , $ model );
120
122
121
- if ($ this ->getBindUserToModel ()) {
123
+ if ($ this ->getBindUserToModel ()) {
122
124
$ model = $ this ->bindAdldapToModel ($ user , $ model );
123
125
}
124
126
@@ -137,10 +139,10 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
137
139
{
138
140
$ attributes = $ this ->getSyncAttributes ();
139
141
140
- foreach ($ attributes as $ modelField => $ adField ) {
142
+ foreach ($ attributes as $ modelField => $ adField ) {
141
143
$ adValue = $ user ->{$ adField };
142
144
143
- if (is_array ($ adValue )) {
145
+ if (is_array ($ adValue )) {
144
146
// If the AD Value is an array, we'll
145
147
// retrieve the first value.
146
148
$ adValue = Arr::get ($ adValue , 0 );
@@ -150,7 +152,7 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
150
152
}
151
153
152
154
// Only save models that contain changes.
153
- if ($ model instanceof Model && count ($ model ->getDirty ()) > 0 ) {
155
+ if ($ model instanceof Model && count ($ model ->getDirty ()) > 0 ) {
154
156
$ model ->save ();
155
157
}
156
158
0 commit comments