Completed
Push — master ( 3f352d...7de6f7 )
by Lukas
84:08 queued 69:49
created
apps/user_ldap/lib/User/User.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -149,17 +149,17 @@  discard block
 block discarded – undo
149 149
 	 * @return null
150 150
 	 */
151 151
 	public function update() {
152
-		if(is_null($this->dn)) {
152
+		if (is_null($this->dn)) {
153 153
 			return null;
154 154
 		}
155 155
 
156 156
 		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
157 157
 				self::USER_PREFKEY_FIRSTLOGIN, 0);
158 158
 
159
-		if($this->needsRefresh()) {
159
+		if ($this->needsRefresh()) {
160 160
 			$this->updateEmail();
161 161
 			$this->updateQuota();
162
-			if($hasLoggedIn !== 0) {
162
+			if ($hasLoggedIn !== 0) {
163 163
 				//we do not need to try it, when the user has not been logged in
164 164
 				//before, because the file system will not be ready.
165 165
 				$this->updateAvatar();
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 		$this->markRefreshTime();
179 179
 		//Quota
180 180
 		$attr = strtolower($this->connection->ldapQuotaAttribute);
181
-		if(isset($ldapEntry[$attr])) {
181
+		if (isset($ldapEntry[$attr])) {
182 182
 			$this->updateQuota($ldapEntry[$attr][0]);
183 183
 		} else {
184 184
 			if ($this->connection->ldapQuotaDefault !== '') {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 
190 190
 		//Email
191 191
 		$attr = strtolower($this->connection->ldapEmailAttribute);
192
-		if(isset($ldapEntry[$attr])) {
192
+		if (isset($ldapEntry[$attr])) {
193 193
 			$this->updateEmail($ldapEntry[$attr][0]);
194 194
 		}
195 195
 		unset($attr);
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 		//displayName
198 198
 		$displayName = $displayName2 = '';
199 199
 		$attr = strtolower($this->connection->ldapUserDisplayName);
200
-		if(isset($ldapEntry[$attr])) {
200
+		if (isset($ldapEntry[$attr])) {
201 201
 			$displayName = strval($ldapEntry[$attr][0]);
202 202
 		}
203 203
 		$attr = strtolower($this->connection->ldapUserDisplayName2);
204
-		if(isset($ldapEntry[$attr])) {
204
+		if (isset($ldapEntry[$attr])) {
205 205
 			$displayName2 = strval($ldapEntry[$attr][0]);
206 206
 		}
207 207
 		if ($displayName !== '') {
@@ -215,16 +215,16 @@  discard block
 block discarded – undo
215 215
 		unset($attr);
216 216
 
217 217
 		// LDAP Username, needed for s2s sharing
218
-		if(isset($ldapEntry['uid'])) {
218
+		if (isset($ldapEntry['uid'])) {
219 219
 			$this->storeLDAPUserName($ldapEntry['uid'][0]);
220
-		} else if(isset($ldapEntry['samaccountname'])) {
220
+		} else if (isset($ldapEntry['samaccountname'])) {
221 221
 			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
222 222
 		}
223 223
 
224 224
 		//homePath
225
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
225
+		if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
226 226
 			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
227
-			if(isset($ldapEntry[$attr])) {
227
+			if (isset($ldapEntry[$attr])) {
228 228
 				$this->access->cacheUserHome(
229 229
 					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
230 230
 			}
@@ -233,15 +233,15 @@  discard block
 block discarded – undo
233 233
 		//memberOf groups
234 234
 		$cacheKey = 'getMemberOf'.$this->getUsername();
235 235
 		$groups = false;
236
-		if(isset($ldapEntry['memberof'])) {
236
+		if (isset($ldapEntry['memberof'])) {
237 237
 			$groups = $ldapEntry['memberof'];
238 238
 		}
239 239
 		$this->connection->writeToCache($cacheKey, $groups);
240 240
 
241 241
 		//Avatar
242 242
 		$attrs = array('jpegphoto', 'thumbnailphoto');
243
-		foreach ($attrs as $attr)  {
244
-			if(isset($ldapEntry[$attr])) {
243
+		foreach ($attrs as $attr) {
244
+			if (isset($ldapEntry[$attr])) {
245 245
 				$this->avatarImage = $ldapEntry[$attr][0];
246 246
 				// the call to the method that saves the avatar in the file
247 247
 				// system must be postponed after the login. It is to ensure
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
 		if ($path !== '') {
295 295
 			//if attribute's value is an absolute path take this, otherwise append it to data dir
296 296
 			//check for / at the beginning or pattern c:\ resp. c:/
297
-			if(   '/' !== $path[0]
297
+			if ('/' !== $path[0]
298 298
 			   && !(3 < strlen($path) && ctype_alpha($path[0])
299 299
 			       && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
300 300
 			) {
301 301
 				$path = $this->config->getSystemValue('datadirectory',
302
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
302
+						\OC::$SERVERROOT.'/data').'/'.$path;
303 303
 			}
304 304
 			//we need it to store it in the DB as well in case a user gets
305 305
 			//deleted so we can clean up afterwards
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
 			return $path;
310 310
 		}
311 311
 
312
-		if(    !is_null($attr)
312
+		if (!is_null($attr)
313 313
 			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
314 314
 		) {
315 315
 			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
316
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
316
+			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername());
317 317
 		}
318 318
 
319 319
 		//false will apply default behaviour as defined and done by OC_User
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	public function getMemberOfGroups() {
325 325
 		$cacheKey = 'getMemberOf'.$this->getUsername();
326 326
 		$memberOfGroups = $this->connection->getFromCache($cacheKey);
327
-		if(!is_null($memberOfGroups)) {
327
+		if (!is_null($memberOfGroups)) {
328 328
 			return $memberOfGroups;
329 329
 		}
330 330
 		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
@@ -337,15 +337,15 @@  discard block
 block discarded – undo
337 337
 	 * @return string data (provided by LDAP) | false
338 338
 	 */
339 339
 	public function getAvatarImage() {
340
-		if(!is_null($this->avatarImage)) {
340
+		if (!is_null($this->avatarImage)) {
341 341
 			return $this->avatarImage;
342 342
 		}
343 343
 
344 344
 		$this->avatarImage = false;
345 345
 		$attributes = array('jpegPhoto', 'thumbnailPhoto');
346
-		foreach($attributes as $attribute) {
346
+		foreach ($attributes as $attribute) {
347 347
 			$result = $this->access->readAttribute($this->dn, $attribute);
348
-			if($result !== false && is_array($result) && isset($result[0])) {
348
+			if ($result !== false && is_array($result) && isset($result[0])) {
349 349
 				$this->avatarImage = $result[0];
350 350
 				break;
351 351
 			}
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 			self::USER_PREFKEY_LASTREFRESH, 0);
384 384
 
385 385
 		//TODO make interval configurable
386
-		if((time() - intval($lastChecked)) < 86400 ) {
386
+		if ((time() - intval($lastChecked)) < 86400) {
387 387
 			return false;
388 388
 		}
389 389
 		return  true;
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 */
410 410
 	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
411 411
 		$displayName2 = strval($displayName2);
412
-		if($displayName2 !== '') {
413
-			$displayName .= ' (' . $displayName2 . ')';
412
+		if ($displayName2 !== '') {
413
+			$displayName .= ' ('.$displayName2.')';
414 414
 		}
415 415
 		$this->store('displayName', $displayName);
416 416
 		return $displayName;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 * @return bool
433 433
 	 */
434 434
 	private function wasRefreshed($feature) {
435
-		if(isset($this->refreshedFeatures[$feature])) {
435
+		if (isset($this->refreshedFeatures[$feature])) {
436 436
 			return true;
437 437
 		}
438 438
 		$this->refreshedFeatures[$feature] = 1;
@@ -445,15 +445,15 @@  discard block
 block discarded – undo
445 445
 	 * @return null
446 446
 	 */
447 447
 	public function updateEmail($valueFromLDAP = null) {
448
-		if($this->wasRefreshed('email')) {
448
+		if ($this->wasRefreshed('email')) {
449 449
 			return;
450 450
 		}
451 451
 		$email = strval($valueFromLDAP);
452
-		if(is_null($valueFromLDAP)) {
452
+		if (is_null($valueFromLDAP)) {
453 453
 			$emailAttribute = $this->connection->ldapEmailAttribute;
454 454
 			if ($emailAttribute !== '') {
455 455
 				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
456
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
456
+				if (is_array($aEmail) && (count($aEmail) > 0)) {
457 457
 					$email = strval($aEmail[0]);
458 458
 				}
459 459
 			}
@@ -490,20 +490,20 @@  discard block
 block discarded – undo
490 490
 	 * @return null
491 491
 	 */
492 492
 	public function updateQuota($valueFromLDAP = null) {
493
-		if($this->wasRefreshed('quota')) {
493
+		if ($this->wasRefreshed('quota')) {
494 494
 			return;
495 495
 		}
496 496
 
497 497
 		$quota = false;
498
-		if(is_null($valueFromLDAP)) {
498
+		if (is_null($valueFromLDAP)) {
499 499
 			$quotaAttribute = $this->connection->ldapQuotaAttribute;
500 500
 			if ($quotaAttribute !== '') {
501 501
 				$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
502
-				if($aQuota && (count($aQuota) > 0)) {
502
+				if ($aQuota && (count($aQuota) > 0)) {
503 503
 					if ($this->verifyQuotaValue($aQuota[0])) {
504 504
 						$quota = $aQuota[0];
505 505
 					} else {
506
-						$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', \OCP\Util::WARN);
506
+						$this->log->log('not suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', \OCP\Util::WARN);
507 507
 					}
508 508
 				}
509 509
 			}
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 			if ($this->verifyQuotaValue($valueFromLDAP)) {
512 512
 				$quota = $valueFromLDAP;
513 513
 			} else {
514
-				$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', \OCP\Util::WARN);
514
+				$this->log->log('not suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', \OCP\Util::WARN);
515 515
 			}
516 516
 		}
517 517
 
@@ -525,13 +525,13 @@  discard block
 block discarded – undo
525 525
 
526 526
 		$targetUser = $this->userManager->get($this->uid);
527 527
 		if ($targetUser) {
528
-			if($quota !== false) {
528
+			if ($quota !== false) {
529 529
 				$targetUser->setQuota($quota);
530 530
 			} else {
531
-				$this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', \OCP\Util::WARN);
531
+				$this->log->log('not suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', \OCP\Util::WARN);
532 532
 			}
533 533
 		} else {
534
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', \OCP\Util::ERROR);
534
+			$this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', \OCP\Util::ERROR);
535 535
 		}
536 536
 	}
537 537
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	 * @param array $params
546 546
 	 */
547 547
 	public function updateAvatarPostLogin($params) {
548
-		if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
548
+		if (isset($params['uid']) && $params['uid'] === $this->getUsername()) {
549 549
 			$this->updateAvatar();
550 550
 		}
551 551
 	}
@@ -555,11 +555,11 @@  discard block
 block discarded – undo
555 555
 	 * @return null
556 556
 	 */
557 557
 	public function updateAvatar() {
558
-		if($this->wasRefreshed('avatar')) {
558
+		if ($this->wasRefreshed('avatar')) {
559 559
 			return;
560 560
 		}
561 561
 		$avatarImage = $this->getAvatarImage();
562
-		if($avatarImage === false) {
562
+		if ($avatarImage === false) {
563 563
 			//not set, nothing left to do;
564 564
 			return;
565 565
 		}
@@ -572,18 +572,18 @@  discard block
 block discarded – undo
572 572
 	 * @return null
573 573
 	 */
574 574
 	private function setOwnCloudAvatar() {
575
-		if(!$this->image->valid()) {
575
+		if (!$this->image->valid()) {
576 576
 			$this->log->log('jpegPhoto data invalid for '.$this->dn, \OCP\Util::ERROR);
577 577
 			return;
578 578
 		}
579 579
 		//make sure it is a square and not bigger than 128x128
580 580
 		$size = min(array($this->image->width(), $this->image->height(), 128));
581
-		if(!$this->image->centerCrop($size)) {
581
+		if (!$this->image->centerCrop($size)) {
582 582
 			$this->log->log('croping image for avatar failed for '.$this->dn, \OCP\Util::ERROR);
583 583
 			return;
584 584
 		}
585 585
 
586
-		if(!$this->fs->isLoaded()) {
586
+		if (!$this->fs->isLoaded()) {
587 587
 			$this->fs->setup($this->uid);
588 588
 		}
589 589
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 			$avatar->set($this->image);
593 593
 		} catch (\Exception $e) {
594 594
 			\OC::$server->getLogger()->notice(
595
-				'Could not set avatar for ' . $this->dn	. ', because: ' . $e->getMessage(),
595
+				'Could not set avatar for '.$this->dn.', because: '.$e->getMessage(),
596 596
 				['app' => 'user_ldap']);
597 597
 		}
598 598
 	}
@@ -605,17 +605,17 @@  discard block
 block discarded – undo
605 605
 	public function handlePasswordExpiry($params) {
606 606
 		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
607 607
 		if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) {
608
-			return;//password expiry handling disabled
608
+			return; //password expiry handling disabled
609 609
 		}
610 610
 		$uid = $params['uid'];
611
-		if(isset($uid) && $uid === $this->getUsername()) {
611
+		if (isset($uid) && $uid === $this->getUsername()) {
612 612
 			//retrieve relevant user attributes
613 613
 			$result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
614 614
 			
615
-			if(array_key_exists('pwdpolicysubentry', $result[0])) {
615
+			if (array_key_exists('pwdpolicysubentry', $result[0])) {
616 616
 				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
617
-				if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
618
-					$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
617
+				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) {
618
+					$ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN
619 619
 				}
620 620
 			}
621 621
 			
@@ -624,9 +624,9 @@  discard block
 block discarded – undo
624 624
 			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
625 625
 			
626 626
 			//retrieve relevant password policy attributes
627
-			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
627
+			$cacheKey = 'ppolicyAttributes'.$ppolicyDN;
628 628
 			$result = $this->connection->getFromCache($cacheKey);
629
-			if(is_null($result)) {
629
+			if (is_null($result)) {
630 630
 				$result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
631 631
 				$this->connection->writeToCache($cacheKey, $result);
632 632
 			}
@@ -637,8 +637,8 @@  discard block
 block discarded – undo
637 637
 			
638 638
 			//handle grace login
639 639
 			$pwdGraceUseTimeCount = count($pwdGraceUseTime);
640
-			if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
641
-				if($pwdGraceAuthNLimit 
640
+			if ($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
641
+				if ($pwdGraceAuthNLimit 
642 642
 					&& (count($pwdGraceAuthNLimit) > 0)
643 643
 					&&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available?
644 644
 					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
@@ -651,24 +651,24 @@  discard block
 block discarded – undo
651 651
 				exit();
652 652
 			}
653 653
 			//handle pwdReset attribute
654
-			if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
654
+			if ($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
655 655
 				$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
656 656
 				header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
657 657
 				'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
658 658
 				exit();
659 659
 			}
660 660
 			//handle password expiry warning
661
-			if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
662
-				if($pwdMaxAge && (count($pwdMaxAge) > 0)
661
+			if ($pwdChangedTime && (count($pwdChangedTime) > 0)) {
662
+				if ($pwdMaxAge && (count($pwdMaxAge) > 0)
663 663
 					&& $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
664 664
 					$pwdMaxAgeInt = intval($pwdMaxAge[0]);
665 665
 					$pwdExpireWarningInt = intval($pwdExpireWarning[0]);
666
-					if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
666
+					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) {
667 667
 						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
668 668
 						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
669 669
 						$currentDateTime = new \DateTime();
670 670
 						$secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
671
-						if($secondsToExpiry <= $pwdExpireWarningInt) {
671
+						if ($secondsToExpiry <= $pwdExpireWarningInt) {
672 672
 							//remove last password expiry warning if any
673 673
 							$notification = $this->notificationManager->createNotification();
674 674
 							$notification->setApp('user_ldap')
Please login to merge, or discard this patch.