Completed
Pull Request — master (#6678)
by Blizzz
26:55 queued 11:21
created
apps/user_ldap/lib/User/User.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -152,17 +152,17 @@  discard block
 block discarded – undo
152 152
 	 * @return null
153 153
 	 */
154 154
 	public function update() {
155
-		if(is_null($this->dn)) {
155
+		if (is_null($this->dn)) {
156 156
 			return null;
157 157
 		}
158 158
 
159 159
 		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
160 160
 				self::USER_PREFKEY_FIRSTLOGIN, 0);
161 161
 
162
-		if($this->needsRefresh()) {
162
+		if ($this->needsRefresh()) {
163 163
 			$this->updateEmail();
164 164
 			$this->updateQuota();
165
-			if($hasLoggedIn !== 0) {
165
+			if ($hasLoggedIn !== 0) {
166 166
 				//we do not need to try it, when the user has not been logged in
167 167
 				//before, because the file system will not be ready.
168 168
 				$this->updateAvatar();
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		$this->markRefreshTime();
182 182
 		//Quota
183 183
 		$attr = strtolower($this->connection->ldapQuotaAttribute);
184
-		if(isset($ldapEntry[$attr])) {
184
+		if (isset($ldapEntry[$attr])) {
185 185
 			$this->updateQuota($ldapEntry[$attr][0]);
186 186
 		} else {
187 187
 			if ($this->connection->ldapQuotaDefault !== '') {
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 		//displayName
194 194
 		$displayName = $displayName2 = '';
195 195
 		$attr = strtolower($this->connection->ldapUserDisplayName);
196
-		if(isset($ldapEntry[$attr])) {
196
+		if (isset($ldapEntry[$attr])) {
197 197
 			$displayName = strval($ldapEntry[$attr][0]);
198 198
 		}
199 199
 		$attr = strtolower($this->connection->ldapUserDisplayName2);
200
-		if(isset($ldapEntry[$attr])) {
200
+		if (isset($ldapEntry[$attr])) {
201 201
 			$displayName2 = strval($ldapEntry[$attr][0]);
202 202
 		}
203 203
 		if ($displayName !== '') {
@@ -214,22 +214,22 @@  discard block
 block discarded – undo
214 214
 		//email must be stored after displayname, because it would cause a user
215 215
 		//change event that will trigger fetching the display name again
216 216
 		$attr = strtolower($this->connection->ldapEmailAttribute);
217
-		if(isset($ldapEntry[$attr])) {
217
+		if (isset($ldapEntry[$attr])) {
218 218
 			$this->updateEmail($ldapEntry[$attr][0]);
219 219
 		}
220 220
 		unset($attr);
221 221
 
222 222
 		// LDAP Username, needed for s2s sharing
223
-		if(isset($ldapEntry['uid'])) {
223
+		if (isset($ldapEntry['uid'])) {
224 224
 			$this->storeLDAPUserName($ldapEntry['uid'][0]);
225
-		} else if(isset($ldapEntry['samaccountname'])) {
225
+		} else if (isset($ldapEntry['samaccountname'])) {
226 226
 			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
227 227
 		}
228 228
 
229 229
 		//homePath
230
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
230
+		if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
231 231
 			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
232
-			if(isset($ldapEntry[$attr])) {
232
+			if (isset($ldapEntry[$attr])) {
233 233
 				$this->access->cacheUserHome(
234 234
 					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
235 235
 			}
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
 		//memberOf groups
239 239
 		$cacheKey = 'getMemberOf'.$this->getUsername();
240 240
 		$groups = false;
241
-		if(isset($ldapEntry['memberof'])) {
241
+		if (isset($ldapEntry['memberof'])) {
242 242
 			$groups = $ldapEntry['memberof'];
243 243
 		}
244 244
 		$this->connection->writeToCache($cacheKey, $groups);
245 245
 
246 246
 		//Avatar
247 247
 		$attrs = array('jpegphoto', 'thumbnailphoto');
248
-		foreach ($attrs as $attr)  {
249
-			if(isset($ldapEntry[$attr])) {
248
+		foreach ($attrs as $attr) {
249
+			if (isset($ldapEntry[$attr])) {
250 250
 				$this->avatarImage = $ldapEntry[$attr][0];
251 251
 				// the call to the method that saves the avatar in the file
252 252
 				// system must be postponed after the login. It is to ensure
@@ -299,12 +299,12 @@  discard block
 block discarded – undo
299 299
 		if ($path !== '') {
300 300
 			//if attribute's value is an absolute path take this, otherwise append it to data dir
301 301
 			//check for / at the beginning or pattern c:\ resp. c:/
302
-			if(   '/' !== $path[0]
302
+			if ('/' !== $path[0]
303 303
 			   && !(3 < strlen($path) && ctype_alpha($path[0])
304 304
 			       && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
305 305
 			) {
306 306
 				$path = $this->config->getSystemValue('datadirectory',
307
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
307
+						\OC::$SERVERROOT.'/data').'/'.$path;
308 308
 			}
309 309
 			//we need it to store it in the DB as well in case a user gets
310 310
 			//deleted so we can clean up afterwards
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
 			return $path;
315 315
 		}
316 316
 
317
-		if(    !is_null($attr)
317
+		if (!is_null($attr)
318 318
 			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
319 319
 		) {
320 320
 			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
321
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
321
+			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername());
322 322
 		}
323 323
 
324 324
 		//false will apply default behaviour as defined and done by OC_User
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 	public function getMemberOfGroups() {
330 330
 		$cacheKey = 'getMemberOf'.$this->getUsername();
331 331
 		$memberOfGroups = $this->connection->getFromCache($cacheKey);
332
-		if(!is_null($memberOfGroups)) {
332
+		if (!is_null($memberOfGroups)) {
333 333
 			return $memberOfGroups;
334 334
 		}
335 335
 		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
@@ -342,15 +342,15 @@  discard block
 block discarded – undo
342 342
 	 * @return string data (provided by LDAP) | false
343 343
 	 */
344 344
 	public function getAvatarImage() {
345
-		if(!is_null($this->avatarImage)) {
345
+		if (!is_null($this->avatarImage)) {
346 346
 			return $this->avatarImage;
347 347
 		}
348 348
 
349 349
 		$this->avatarImage = false;
350 350
 		$attributes = array('jpegPhoto', 'thumbnailPhoto');
351
-		foreach($attributes as $attribute) {
351
+		foreach ($attributes as $attribute) {
352 352
 			$result = $this->access->readAttribute($this->dn, $attribute);
353
-			if($result !== false && is_array($result) && isset($result[0])) {
353
+			if ($result !== false && is_array($result) && isset($result[0])) {
354 354
 				$this->avatarImage = $result[0];
355 355
 				break;
356 356
 			}
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 		$lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
388 388
 			self::USER_PREFKEY_LASTREFRESH, 0);
389 389
 
390
-		if((time() - intval($lastChecked)) < intval($this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) ) {
390
+		if ((time() - intval($lastChecked)) < intval($this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400))) {
391 391
 			return false;
392 392
 		}
393 393
 		return  true;
@@ -413,8 +413,8 @@  discard block
 block discarded – undo
413 413
 	 */
414 414
 	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
415 415
 		$displayName2 = strval($displayName2);
416
-		if($displayName2 !== '') {
417
-			$displayName .= ' (' . $displayName2 . ')';
416
+		if ($displayName2 !== '') {
417
+			$displayName .= ' ('.$displayName2.')';
418 418
 		}
419 419
 		$this->store('displayName', $displayName);
420 420
 		return $displayName;
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 	 * @return bool
437 437
 	 */
438 438
 	private function wasRefreshed($feature) {
439
-		if(isset($this->refreshedFeatures[$feature])) {
439
+		if (isset($this->refreshedFeatures[$feature])) {
440 440
 			return true;
441 441
 		}
442 442
 		$this->refreshedFeatures[$feature] = 1;
@@ -449,15 +449,15 @@  discard block
 block discarded – undo
449 449
 	 * @return null
450 450
 	 */
451 451
 	public function updateEmail($valueFromLDAP = null) {
452
-		if($this->wasRefreshed('email')) {
452
+		if ($this->wasRefreshed('email')) {
453 453
 			return;
454 454
 		}
455 455
 		$email = strval($valueFromLDAP);
456
-		if(is_null($valueFromLDAP)) {
456
+		if (is_null($valueFromLDAP)) {
457 457
 			$emailAttribute = $this->connection->ldapEmailAttribute;
458 458
 			if ($emailAttribute !== '') {
459 459
 				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
460
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
460
+				if (is_array($aEmail) && (count($aEmail) > 0)) {
461 461
 					$email = strval($aEmail[0]);
462 462
 				}
463 463
 			}
@@ -494,20 +494,20 @@  discard block
 block discarded – undo
494 494
 	 * @return null
495 495
 	 */
496 496
 	public function updateQuota($valueFromLDAP = null) {
497
-		if($this->wasRefreshed('quota')) {
497
+		if ($this->wasRefreshed('quota')) {
498 498
 			return;
499 499
 		}
500 500
 
501 501
 		$quota = false;
502
-		if(is_null($valueFromLDAP)) {
502
+		if (is_null($valueFromLDAP)) {
503 503
 			$quotaAttribute = $this->connection->ldapQuotaAttribute;
504 504
 			if ($quotaAttribute !== '') {
505 505
 				$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
506
-				if($aQuota && (count($aQuota) > 0)) {
506
+				if ($aQuota && (count($aQuota) > 0)) {
507 507
 					if ($this->verifyQuotaValue($aQuota[0])) {
508 508
 						$quota = $aQuota[0];
509 509
 					} else {
510
-						$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', \OCP\Util::WARN);
510
+						$this->log->log('not suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', \OCP\Util::WARN);
511 511
 					}
512 512
 				}
513 513
 			}
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 			if ($this->verifyQuotaValue($valueFromLDAP)) {
516 516
 				$quota = $valueFromLDAP;
517 517
 			} else {
518
-				$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', \OCP\Util::WARN);
518
+				$this->log->log('not suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', \OCP\Util::WARN);
519 519
 			}
520 520
 		}
521 521
 
@@ -529,13 +529,13 @@  discard block
 block discarded – undo
529 529
 
530 530
 		$targetUser = $this->userManager->get($this->uid);
531 531
 		if ($targetUser) {
532
-			if($quota !== false) {
532
+			if ($quota !== false) {
533 533
 				$targetUser->setQuota($quota);
534 534
 			} else {
535
-				$this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', \OCP\Util::WARN);
535
+				$this->log->log('not suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', \OCP\Util::WARN);
536 536
 			}
537 537
 		} else {
538
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', \OCP\Util::ERROR);
538
+			$this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', \OCP\Util::ERROR);
539 539
 		}
540 540
 	}
541 541
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 	 * @param array $params
550 550
 	 */
551 551
 	public function updateAvatarPostLogin($params) {
552
-		if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
552
+		if (isset($params['uid']) && $params['uid'] === $this->getUsername()) {
553 553
 			$this->updateAvatar();
554 554
 		}
555 555
 	}
@@ -559,11 +559,11 @@  discard block
 block discarded – undo
559 559
 	 * @return null
560 560
 	 */
561 561
 	public function updateAvatar() {
562
-		if($this->wasRefreshed('avatar')) {
562
+		if ($this->wasRefreshed('avatar')) {
563 563
 			return;
564 564
 		}
565 565
 		$avatarImage = $this->getAvatarImage();
566
-		if($avatarImage === false) {
566
+		if ($avatarImage === false) {
567 567
 			//not set, nothing left to do;
568 568
 			return;
569 569
 		}
@@ -576,18 +576,18 @@  discard block
 block discarded – undo
576 576
 	 * @return null
577 577
 	 */
578 578
 	private function setOwnCloudAvatar() {
579
-		if(!$this->image->valid()) {
579
+		if (!$this->image->valid()) {
580 580
 			$this->log->log('jpegPhoto data invalid for '.$this->dn, \OCP\Util::ERROR);
581 581
 			return;
582 582
 		}
583 583
 		//make sure it is a square and not bigger than 128x128
584 584
 		$size = min(array($this->image->width(), $this->image->height(), 128));
585
-		if(!$this->image->centerCrop($size)) {
585
+		if (!$this->image->centerCrop($size)) {
586 586
 			$this->log->log('croping image for avatar failed for '.$this->dn, \OCP\Util::ERROR);
587 587
 			return;
588 588
 		}
589 589
 
590
-		if(!$this->fs->isLoaded()) {
590
+		if (!$this->fs->isLoaded()) {
591 591
 			$this->fs->setup($this->uid);
592 592
 		}
593 593
 
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 			$avatar->set($this->image);
597 597
 		} catch (\Exception $e) {
598 598
 			\OC::$server->getLogger()->notice(
599
-				'Could not set avatar for ' . $this->dn	. ', because: ' . $e->getMessage(),
599
+				'Could not set avatar for '.$this->dn.', because: '.$e->getMessage(),
600 600
 				['app' => 'user_ldap']);
601 601
 		}
602 602
 	}
@@ -609,17 +609,17 @@  discard block
 block discarded – undo
609 609
 	public function handlePasswordExpiry($params) {
610 610
 		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
611 611
 		if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) {
612
-			return;//password expiry handling disabled
612
+			return; //password expiry handling disabled
613 613
 		}
614 614
 		$uid = $params['uid'];
615
-		if(isset($uid) && $uid === $this->getUsername()) {
615
+		if (isset($uid) && $uid === $this->getUsername()) {
616 616
 			//retrieve relevant user attributes
617 617
 			$result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
618 618
 			
619
-			if(array_key_exists('pwdpolicysubentry', $result[0])) {
619
+			if (array_key_exists('pwdpolicysubentry', $result[0])) {
620 620
 				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
621
-				if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
622
-					$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
621
+				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) {
622
+					$ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN
623 623
 				}
624 624
 			}
625 625
 			
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
629 629
 			
630 630
 			//retrieve relevant password policy attributes
631
-			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
631
+			$cacheKey = 'ppolicyAttributes'.$ppolicyDN;
632 632
 			$result = $this->connection->getFromCache($cacheKey);
633
-			if(is_null($result)) {
633
+			if (is_null($result)) {
634 634
 				$result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
635 635
 				$this->connection->writeToCache($cacheKey, $result);
636 636
 			}
@@ -641,8 +641,8 @@  discard block
 block discarded – undo
641 641
 			
642 642
 			//handle grace login
643 643
 			$pwdGraceUseTimeCount = count($pwdGraceUseTime);
644
-			if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
645
-				if($pwdGraceAuthNLimit 
644
+			if ($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
645
+				if ($pwdGraceAuthNLimit 
646 646
 					&& (count($pwdGraceAuthNLimit) > 0)
647 647
 					&&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available?
648 648
 					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
@@ -655,24 +655,24 @@  discard block
 block discarded – undo
655 655
 				exit();
656 656
 			}
657 657
 			//handle pwdReset attribute
658
-			if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
658
+			if ($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
659 659
 				$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
660 660
 				header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
661 661
 				'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
662 662
 				exit();
663 663
 			}
664 664
 			//handle password expiry warning
665
-			if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
666
-				if($pwdMaxAge && (count($pwdMaxAge) > 0)
665
+			if ($pwdChangedTime && (count($pwdChangedTime) > 0)) {
666
+				if ($pwdMaxAge && (count($pwdMaxAge) > 0)
667 667
 					&& $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
668 668
 					$pwdMaxAgeInt = intval($pwdMaxAge[0]);
669 669
 					$pwdExpireWarningInt = intval($pwdExpireWarning[0]);
670
-					if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
670
+					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) {
671 671
 						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
672 672
 						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
673 673
 						$currentDateTime = new \DateTime();
674 674
 						$secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
675
-						if($secondsToExpiry <= $pwdExpireWarningInt) {
675
+						if ($secondsToExpiry <= $pwdExpireWarningInt) {
676 676
 							//remove last password expiry warning if any
677 677
 							$notification = $this->notificationManager->createNotification();
678 678
 							$notification->setApp('user_ldap')
Please login to merge, or discard this patch.