@@ -48,7 +48,7 @@ __Attention!__ You need to define `baseDn`. This defines the baseDN in where the
48
48
49
49
## Usage
50
50
51
- There are 4 basic functions:
51
+ There are 5 basic functions:
52
52
53
53
* ` autoDetect($overrideIp) `
54
54
* Tries to detect the User's client IP (with Proxy support) and determines the Domain to use
@@ -69,6 +69,9 @@ There are 4 basic functions:
69
69
domain
70
70
* ` $onlyActiveAccounts ` lets you decide whether you only want active or all accounts to be returned. defaults to
71
71
false!
72
+ * ` updateAttributes ` lets you update the user attributes
73
+ * ` $attributes ` The attribute (array keys are the attribute names, the array values are the attribute values)
74
+ * ` $dn ` The DN which should be updated - if not provided, the eventually previous examined one will be used.
72
75
73
76
## Example
74
77
@@ -142,15 +145,41 @@ public function login()
142
145
143
146
This also tries to sync user's data with the LDAP.
144
147
148
+ ### User attribute update
149
+
150
+ ``` php
151
+ /** @var LdapAuth $ldap */
152
+ $ldap = \Yii::$app->ldap;
153
+
154
+ if (!$ldap->login(\Yii::$app->user->identity->sid, $this->userPassword, false, true)) {
155
+ return false;
156
+ }
157
+
158
+ $updateAttrs = [];
159
+
160
+ if (!empty($this->phone)) {
161
+ $updateAttrs['telephonenumber'] = $this->phone;
162
+ }
163
+
164
+ if (!empty($this->room)) {
165
+ $updateAttrs['physicaldeliveryofficename'] = $this->room;
166
+ }
167
+
168
+ if (!$ldap->updateAttributes($updateAttrs)) {
169
+ return false;
170
+ }
171
+ ```
172
+
145
173
## The database
146
174
147
175
I've added/changed the user table as follow, to add a sid, firstname, lastname and phone column:
148
176
149
177
``` sql
150
- CREATE TABLE `user ` (
151
- ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
152
- ` sid` varchar (255 ) DEFAULT NULL ,
153
- ` email` varchar (256 ) NOT NULL ,
178
+ CREATE TABLE `user `
179
+ (
180
+ ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
181
+ ` sid` varchar (255 ) DEFAULT NULL ,
182
+ ` email` varchar (256 ) NOT NULL ,
154
183
` firstname` varchar (255 ) DEFAULT NULL ,
155
184
` lastname` varchar (255 ) DEFAULT NULL ,
156
185
` phone` varchar (255 ) DEFAULT NULL ,
0 commit comments