Passed
Push — master ( 25ab12...62403d )
by Blizzz
12:17 queued 22s
created
apps/user_ldap/lib/User/User.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
 	 * @return null
155 155
 	 */
156 156
 	public function update() {
157
-		if(is_null($this->dn)) {
157
+		if (is_null($this->dn)) {
158 158
 			return null;
159 159
 		}
160 160
 
161 161
 		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
162 162
 				self::USER_PREFKEY_FIRSTLOGIN, 0);
163 163
 
164
-		if($this->needsRefresh()) {
164
+		if ($this->needsRefresh()) {
165 165
 			$this->updateEmail();
166 166
 			$this->updateQuota();
167
-			if($hasLoggedIn !== 0) {
167
+			if ($hasLoggedIn !== 0) {
168 168
 				//we do not need to try it, when the user has not been logged in
169 169
 				//before, because the file system will not be ready.
170 170
 				$this->updateAvatar();
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
 	 */
183 183
 	public function markUser() {
184 184
 		$curValue = $this->config->getUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '0');
185
-		if($curValue === '1') {
185
+		if ($curValue === '1') {
186 186
 			// the user is already marked, do not write to DB again
187 187
 			return;
188 188
 		}
189 189
 		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '1');
190
-		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'foundDeleted', (string)time());
190
+		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'foundDeleted', (string) time());
191 191
 	}
192 192
 
193 193
 	/**
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		$this->markRefreshTime();
199 199
 		//Quota
200 200
 		$attr = strtolower($this->connection->ldapQuotaAttribute);
201
-		if(isset($ldapEntry[$attr])) {
201
+		if (isset($ldapEntry[$attr])) {
202 202
 			$this->updateQuota($ldapEntry[$attr][0]);
203 203
 		} else {
204 204
 			if ($this->connection->ldapQuotaDefault !== '') {
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
 		//displayName
211 211
 		$displayName = $displayName2 = '';
212 212
 		$attr = strtolower($this->connection->ldapUserDisplayName);
213
-		if(isset($ldapEntry[$attr])) {
214
-			$displayName = (string)$ldapEntry[$attr][0];
213
+		if (isset($ldapEntry[$attr])) {
214
+			$displayName = (string) $ldapEntry[$attr][0];
215 215
 		}
216 216
 		$attr = strtolower($this->connection->ldapUserDisplayName2);
217
-		if(isset($ldapEntry[$attr])) {
218
-			$displayName2 = (string)$ldapEntry[$attr][0];
217
+		if (isset($ldapEntry[$attr])) {
218
+			$displayName2 = (string) $ldapEntry[$attr][0];
219 219
 		}
220 220
 		if ($displayName !== '') {
221 221
 			$this->composeAndStoreDisplayName($displayName, $displayName2);
@@ -231,22 +231,22 @@  discard block
 block discarded – undo
231 231
 		//email must be stored after displayname, because it would cause a user
232 232
 		//change event that will trigger fetching the display name again
233 233
 		$attr = strtolower($this->connection->ldapEmailAttribute);
234
-		if(isset($ldapEntry[$attr])) {
234
+		if (isset($ldapEntry[$attr])) {
235 235
 			$this->updateEmail($ldapEntry[$attr][0]);
236 236
 		}
237 237
 		unset($attr);
238 238
 
239 239
 		// LDAP Username, needed for s2s sharing
240
-		if(isset($ldapEntry['uid'])) {
240
+		if (isset($ldapEntry['uid'])) {
241 241
 			$this->storeLDAPUserName($ldapEntry['uid'][0]);
242
-		} else if(isset($ldapEntry['samaccountname'])) {
242
+		} else if (isset($ldapEntry['samaccountname'])) {
243 243
 			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
244 244
 		}
245 245
 
246 246
 		//homePath
247
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
247
+		if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
248 248
 			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
249
-			if(isset($ldapEntry[$attr])) {
249
+			if (isset($ldapEntry[$attr])) {
250 250
 				$this->access->cacheUserHome(
251 251
 					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
252 252
 			}
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
 		//memberOf groups
256 256
 		$cacheKey = 'getMemberOf'.$this->getUsername();
257 257
 		$groups = false;
258
-		if(isset($ldapEntry['memberof'])) {
258
+		if (isset($ldapEntry['memberof'])) {
259 259
 			$groups = $ldapEntry['memberof'];
260 260
 		}
261 261
 		$this->connection->writeToCache($cacheKey, $groups);
262 262
 
263 263
 		//external storage var
264 264
 		$attr = strtolower($this->connection->ldapExtStorageHomeAttribute);
265
-		if(isset($ldapEntry[$attr])) {
265
+		if (isset($ldapEntry[$attr])) {
266 266
 			$this->updateExtStorageHome($ldapEntry[$attr][0]);
267 267
 		}
268 268
 		unset($attr);
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 		/** @var Connection $connection */
272 272
 		$connection = $this->access->getConnection();
273 273
 		$attributes = $connection->resolveRule('avatar');
274
-		foreach ($attributes as $attribute)  {
275
-			if(isset($ldapEntry[$attribute])) {
274
+		foreach ($attributes as $attribute) {
275
+			if (isset($ldapEntry[$attribute])) {
276 276
 				$this->avatarImage = $ldapEntry[$attribute][0];
277 277
 				// the call to the method that saves the avatar in the file
278 278
 				// system must be postponed after the login. It is to ensure
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 	 * @throws \Exception
308 308
 	 */
309 309
 	public function getHomePath($valueFromLDAP = null) {
310
-		$path = (string)$valueFromLDAP;
310
+		$path = (string) $valueFromLDAP;
311 311
 		$attr = null;
312 312
 
313 313
 		if (is_null($valueFromLDAP)
@@ -325,12 +325,12 @@  discard block
 block discarded – undo
325 325
 		if ($path !== '') {
326 326
 			//if attribute's value is an absolute path take this, otherwise append it to data dir
327 327
 			//check for / at the beginning or pattern c:\ resp. c:/
328
-			if(   '/' !== $path[0]
328
+			if ('/' !== $path[0]
329 329
 			   && !(3 < strlen($path) && ctype_alpha($path[0])
330 330
 			       && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
331 331
 			) {
332 332
 				$path = $this->config->getSystemValue('datadirectory',
333
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
333
+						\OC::$SERVERROOT.'/data').'/'.$path;
334 334
 			}
335 335
 			//we need it to store it in the DB as well in case a user gets
336 336
 			//deleted so we can clean up afterwards
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
 			return $path;
341 341
 		}
342 342
 
343
-		if(    !is_null($attr)
343
+		if (!is_null($attr)
344 344
 			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
345 345
 		) {
346 346
 			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
347
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
347
+			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername());
348 348
 		}
349 349
 
350 350
 		//false will apply default behaviour as defined and done by OC_User
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	public function getMemberOfGroups() {
356 356
 		$cacheKey = 'getMemberOf'.$this->getUsername();
357 357
 		$memberOfGroups = $this->connection->getFromCache($cacheKey);
358
-		if(!is_null($memberOfGroups)) {
358
+		if (!is_null($memberOfGroups)) {
359 359
 			return $memberOfGroups;
360 360
 		}
361 361
 		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @return string data (provided by LDAP) | false
369 369
 	 */
370 370
 	public function getAvatarImage() {
371
-		if(!is_null($this->avatarImage)) {
371
+		if (!is_null($this->avatarImage)) {
372 372
 			return $this->avatarImage;
373 373
 		}
374 374
 
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 		/** @var Connection $connection */
377 377
 		$connection = $this->access->getConnection();
378 378
 		$attributes = $connection->resolveRule('avatar');
379
-		foreach($attributes as $attribute) {
379
+		foreach ($attributes as $attribute) {
380 380
 			$result = $this->access->readAttribute($this->dn, $attribute);
381
-			if($result !== false && is_array($result) && isset($result[0])) {
381
+			if ($result !== false && is_array($result) && isset($result[0])) {
382 382
 				$this->avatarImage = $result[0];
383 383
 				break;
384 384
 			}
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 		$lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
416 416
 			self::USER_PREFKEY_LASTREFRESH, 0);
417 417
 
418
-		if((time() - (int)$lastChecked) < (int)$this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) {
418
+		if ((time() - (int) $lastChecked) < (int) $this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) {
419 419
 			return false;
420 420
 		}
421 421
 		return  true;
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	 * @return string the effective display name
441 441
 	 */
442 442
 	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
443
-		$displayName2 = (string)$displayName2;
444
-		if($displayName2 !== '') {
445
-			$displayName .= ' (' . $displayName2 . ')';
443
+		$displayName2 = (string) $displayName2;
444
+		if ($displayName2 !== '') {
445
+			$displayName .= ' ('.$displayName2.')';
446 446
 		}
447 447
 		$oldName = $this->config->getUserValue($this->uid, 'user_ldap', 'displayName', null);
448
-		if ($oldName !== $displayName)  {
448
+		if ($oldName !== $displayName) {
449 449
 			$this->store('displayName', $displayName);
450 450
 			$user = $this->userManager->get($this->getUsername());
451 451
 			if (!empty($oldName) && $user instanceof \OC\User\User) {
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	 * @return bool
474 474
 	 */
475 475
 	private function wasRefreshed($feature) {
476
-		if(isset($this->refreshedFeatures[$feature])) {
476
+		if (isset($this->refreshedFeatures[$feature])) {
477 477
 			return true;
478 478
 		}
479 479
 		$this->refreshedFeatures[$feature] = 1;
@@ -486,23 +486,23 @@  discard block
 block discarded – undo
486 486
 	 * @return null
487 487
 	 */
488 488
 	public function updateEmail($valueFromLDAP = null) {
489
-		if($this->wasRefreshed('email')) {
489
+		if ($this->wasRefreshed('email')) {
490 490
 			return;
491 491
 		}
492
-		$email = (string)$valueFromLDAP;
493
-		if(is_null($valueFromLDAP)) {
492
+		$email = (string) $valueFromLDAP;
493
+		if (is_null($valueFromLDAP)) {
494 494
 			$emailAttribute = $this->connection->ldapEmailAttribute;
495 495
 			if ($emailAttribute !== '') {
496 496
 				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
497
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
498
-					$email = (string)$aEmail[0];
497
+				if (is_array($aEmail) && (count($aEmail) > 0)) {
498
+					$email = (string) $aEmail[0];
499 499
 				}
500 500
 			}
501 501
 		}
502 502
 		if ($email !== '') {
503 503
 			$user = $this->userManager->get($this->uid);
504 504
 			if (!is_null($user)) {
505
-				$currentEmail = (string)$user->getEMailAddress();
505
+				$currentEmail = (string) $user->getEMailAddress();
506 506
 				if ($currentEmail !== $email) {
507 507
 					$user->setEMailAddress($email);
508 508
 				}
@@ -531,35 +531,35 @@  discard block
 block discarded – undo
531 531
 	 * @return null
532 532
 	 */
533 533
 	public function updateQuota($valueFromLDAP = null) {
534
-		if($this->wasRefreshed('quota')) {
534
+		if ($this->wasRefreshed('quota')) {
535 535
 			return;
536 536
 		}
537 537
 
538 538
 		$quotaAttribute = $this->connection->ldapQuotaAttribute;
539 539
 		$defaultQuota = $this->connection->ldapQuotaDefault;
540
-		if($quotaAttribute === '' && $defaultQuota === '') {
540
+		if ($quotaAttribute === '' && $defaultQuota === '') {
541 541
 			return;
542 542
 		}
543 543
 
544 544
 		$quota = false;
545
-		if(is_null($valueFromLDAP) && $quotaAttribute !== '') {
545
+		if (is_null($valueFromLDAP) && $quotaAttribute !== '') {
546 546
 			$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
547
-			if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
547
+			if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
548 548
 				$quota = $aQuota[0];
549
-			} else if(is_array($aQuota) && isset($aQuota[0])) {
550
-				$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::DEBUG);
549
+			} else if (is_array($aQuota) && isset($aQuota[0])) {
550
+				$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', ILogger::DEBUG);
551 551
 			}
552 552
 		} else if ($this->verifyQuotaValue($valueFromLDAP)) {
553 553
 			$quota = $valueFromLDAP;
554 554
 		} else {
555
-			$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::DEBUG);
555
+			$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', ILogger::DEBUG);
556 556
 		}
557 557
 
558 558
 		if ($quota === false && $this->verifyQuotaValue($defaultQuota)) {
559 559
 			// quota not found using the LDAP attribute (or not parseable). Try the default quota
560 560
 			$quota = $defaultQuota;
561
-		} else if($quota === false) {
562
-			$this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::DEBUG);
561
+		} else if ($quota === false) {
562
+			$this->log->log('no suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', ILogger::DEBUG);
563 563
 			return;
564 564
 		}
565 565
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 		if ($targetUser instanceof IUser) {
568 568
 			$targetUser->setQuota($quota);
569 569
 		} else {
570
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::INFO);
570
+			$this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', ILogger::INFO);
571 571
 		}
572 572
 	}
573 573
 
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 	 * @param array $params
582 582
 	 */
583 583
 	public function updateAvatarPostLogin($params) {
584
-		if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
584
+		if (isset($params['uid']) && $params['uid'] === $this->getUsername()) {
585 585
 			$this->updateAvatar();
586 586
 		}
587 587
 	}
@@ -591,29 +591,29 @@  discard block
 block discarded – undo
591 591
 	 * @return bool
592 592
 	 */
593 593
 	public function updateAvatar($force = false) {
594
-		if(!$force && $this->wasRefreshed('avatar')) {
594
+		if (!$force && $this->wasRefreshed('avatar')) {
595 595
 			return false;
596 596
 		}
597 597
 		$avatarImage = $this->getAvatarImage();
598
-		if($avatarImage === false) {
598
+		if ($avatarImage === false) {
599 599
 			//not set, nothing left to do;
600 600
 			return false;
601 601
 		}
602 602
 
603
-		if(!$this->image->loadFromBase64(base64_encode($avatarImage))) {
603
+		if (!$this->image->loadFromBase64(base64_encode($avatarImage))) {
604 604
 			return false;
605 605
 		}
606 606
 
607 607
 		// use the checksum before modifications
608 608
 		$checksum = md5($this->image->data());
609 609
 
610
-		if($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) {
610
+		if ($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) {
611 611
 			return true;
612 612
 		}
613 613
 
614 614
 		$isSet = $this->setOwnCloudAvatar();
615 615
 
616
-		if($isSet) {
616
+		if ($isSet) {
617 617
 			// save checksum only after successful setting
618 618
 			$this->config->setUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', $checksum);
619 619
 		}
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 	 * @return bool
627 627
 	 */
628 628
 	private function setOwnCloudAvatar() {
629
-		if(!$this->image->valid()) {
629
+		if (!$this->image->valid()) {
630 630
 			$this->log->log('avatar image data from LDAP invalid for '.$this->dn, ILogger::ERROR);
631 631
 			return false;
632 632
 		}
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
 
635 635
 		//make sure it is a square and not bigger than 128x128
636 636
 		$size = min([$this->image->width(), $this->image->height(), 128]);
637
-		if(!$this->image->centerCrop($size)) {
637
+		if (!$this->image->centerCrop($size)) {
638 638
 			$this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR);
639 639
 			return false;
640 640
 		}
641 641
 
642
-		if(!$this->fs->isLoaded()) {
642
+		if (!$this->fs->isLoaded()) {
643 643
 			$this->fs->setup($this->uid);
644 644
 		}
645 645
 
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 			return true;
650 650
 		} catch (\Exception $e) {
651 651
 			\OC::$server->getLogger()->logException($e, [
652
-				'message' => 'Could not set avatar for ' . $this->dn,
652
+				'message' => 'Could not set avatar for '.$this->dn,
653 653
 				'level' => ILogger::INFO,
654 654
 				'app' => 'user_ldap',
655 655
 			]);
@@ -705,8 +705,8 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
 	public function handlePasswordExpiry($params) {
707 707
 		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
708
-		if (empty($ppolicyDN) || ((int)$this->connection->turnOnPasswordChange !== 1)) {
709
-			return;//password expiry handling disabled
708
+		if (empty($ppolicyDN) || ((int) $this->connection->turnOnPasswordChange !== 1)) {
709
+			return; //password expiry handling disabled
710 710
 		}
711 711
 		$uid = $params['uid'];
712 712
 		if (isset($uid) && $uid === $this->getUsername()) {
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
 
716 716
 			if (array_key_exists('pwdpolicysubentry', $result[0])) {
717 717
 				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
718
-				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
719
-					$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
718
+				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) {
719
+					$ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN
720 720
 				}
721 721
 			}
722 722
 
@@ -725,9 +725,9 @@  discard block
 block discarded – undo
725 725
 			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : [];
726 726
 
727 727
 			//retrieve relevant password policy attributes
728
-			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
728
+			$cacheKey = 'ppolicyAttributes'.$ppolicyDN;
729 729
 			$result = $this->connection->getFromCache($cacheKey);
730
-			if(is_null($result)) {
730
+			if (is_null($result)) {
731 731
 				$result = $this->access->search('objectclass=*', array($ppolicyDN), ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
732 732
 				$this->connection->writeToCache($cacheKey, $result);
733 733
 			}
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 			//handle grace login
740 740
 			if (!empty($pwdGraceUseTime)) { //was this a grace login?
741 741
 				if (!empty($pwdGraceAuthNLimit)
742
-					&& count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available?
742
+					&& count($pwdGraceUseTime) < (int) $pwdGraceAuthNLimit[0]) { //at least one more grace login available?
743 743
 					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
744 744
 					header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
745 745
 					'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
@@ -760,9 +760,9 @@  discard block
 block discarded – undo
760 760
 			if (!empty($pwdChangedTime)) {
761 761
 				if (!empty($pwdMaxAge)
762 762
 					&& !empty($pwdExpireWarning)) {
763
-					$pwdMaxAgeInt = (int)$pwdMaxAge[0];
764
-					$pwdExpireWarningInt = (int)$pwdExpireWarning[0];
765
-					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
763
+					$pwdMaxAgeInt = (int) $pwdMaxAge[0];
764
+					$pwdExpireWarningInt = (int) $pwdExpireWarning[0];
765
+					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) {
766 766
 						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
767 767
 						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
768 768
 						$currentDateTime = new \DateTime();
Please login to merge, or discard this patch.