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,11 +54,11 @@ 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
// We'll make sure we retrieve the users first username
63
63
// attribute if it's contained in an array.
64
64
$ username = Arr::get ($ username , 0 );
@@ -68,18 +68,18 @@ public function retrieveByCredentials(array $credentials)
68
68
$ key = $ this ->getPasswordKey ();
69
69
70
70
// Try to log the user in.
71
- if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
71
+ if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
72
72
// Login was successful, we'll create a new
73
73
// Laravel model with the Adldap user.
74
74
return $ this ->getModelFromAdldap ($ user , $ credentials [$ key ]);
75
75
}
76
76
}
77
77
78
- return null ;
78
+ return ;
79
79
}
80
80
81
81
/**
82
- * Creates a local User from Active Directory
82
+ * Creates a local User from Active Directory.
83
83
*
84
84
* @param User $user
85
85
* @param string $password
@@ -107,7 +107,9 @@ protected function getModelFromAdldap(User $user, $password)
107
107
$ model = $ this ->createModel ()->newQuery ()->where ([$ key => $ username ])->first ();
108
108
109
109
// Create the model instance of it isn't found.
110
- if (!$ model ) $ model = $ this ->createModel ();
110
+ if (!$ model ) {
111
+ $ model = $ this ->createModel ();
112
+ }
111
113
112
114
// Set the username and password in case
113
115
// of changes in active directory.
@@ -120,7 +122,7 @@ protected function getModelFromAdldap(User $user, $password)
120
122
// attributes on the model.
121
123
$ model = $ this ->syncModelFromAdldap ($ user , $ model );
122
124
123
- if ($ this ->getBindUserToModel ()) {
125
+ if ($ this ->getBindUserToModel ()) {
124
126
$ model = $ this ->bindAdldapToModel ($ user , $ model );
125
127
}
126
128
@@ -139,10 +141,10 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
139
141
{
140
142
$ attributes = $ this ->getSyncAttributes ();
141
143
142
- foreach ($ attributes as $ modelField => $ adField ) {
144
+ foreach ($ attributes as $ modelField => $ adField ) {
143
145
$ adValue = $ user ->{$ adField };
144
146
145
- if (is_array ($ adValue )) {
147
+ if (is_array ($ adValue )) {
146
148
// If the AD Value is an array, we'll
147
149
// retrieve the first value.
148
150
$ adValue = Arr::get ($ adValue , 0 );
@@ -151,7 +153,7 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
151
153
$ model ->{$ modelField } = $ adValue ;
152
154
}
153
155
154
- if ($ model instanceof Model) {
156
+ if ($ model instanceof Model) {
155
157
$ model ->save ();
156
158
}
157
159
0 commit comments