Completed
Push — stable13 ( f5bbe2...486dff )
by Blizzz
21:41
created
apps/user_ldap/lib/User/User.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
 	 * @return null
154 154
 	 */
155 155
 	public function update() {
156
-		if(is_null($this->dn)) {
156
+		if (is_null($this->dn)) {
157 157
 			return null;
158 158
 		}
159 159
 
160 160
 		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
161 161
 				self::USER_PREFKEY_FIRSTLOGIN, 0);
162 162
 
163
-		if($this->needsRefresh()) {
163
+		if ($this->needsRefresh()) {
164 164
 			$this->updateEmail();
165 165
 			$this->updateQuota();
166
-			if($hasLoggedIn !== 0) {
166
+			if ($hasLoggedIn !== 0) {
167 167
 				//we do not need to try it, when the user has not been logged in
168 168
 				//before, because the file system will not be ready.
169 169
 				$this->updateAvatar();
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		$this->markRefreshTime();
183 183
 		//Quota
184 184
 		$attr = strtolower($this->connection->ldapQuotaAttribute);
185
-		if(isset($ldapEntry[$attr])) {
185
+		if (isset($ldapEntry[$attr])) {
186 186
 			$this->updateQuota($ldapEntry[$attr][0]);
187 187
 		} else {
188 188
 			if ($this->connection->ldapQuotaDefault !== '') {
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
 		//displayName
195 195
 		$displayName = $displayName2 = '';
196 196
 		$attr = strtolower($this->connection->ldapUserDisplayName);
197
-		if(isset($ldapEntry[$attr])) {
197
+		if (isset($ldapEntry[$attr])) {
198 198
 			$displayName = strval($ldapEntry[$attr][0]);
199 199
 		}
200 200
 		$attr = strtolower($this->connection->ldapUserDisplayName2);
201
-		if(isset($ldapEntry[$attr])) {
201
+		if (isset($ldapEntry[$attr])) {
202 202
 			$displayName2 = strval($ldapEntry[$attr][0]);
203 203
 		}
204 204
 		if ($displayName !== '') {
@@ -215,22 +215,22 @@  discard block
 block discarded – undo
215 215
 		//email must be stored after displayname, because it would cause a user
216 216
 		//change event that will trigger fetching the display name again
217 217
 		$attr = strtolower($this->connection->ldapEmailAttribute);
218
-		if(isset($ldapEntry[$attr])) {
218
+		if (isset($ldapEntry[$attr])) {
219 219
 			$this->updateEmail($ldapEntry[$attr][0]);
220 220
 		}
221 221
 		unset($attr);
222 222
 
223 223
 		// LDAP Username, needed for s2s sharing
224
-		if(isset($ldapEntry['uid'])) {
224
+		if (isset($ldapEntry['uid'])) {
225 225
 			$this->storeLDAPUserName($ldapEntry['uid'][0]);
226
-		} else if(isset($ldapEntry['samaccountname'])) {
226
+		} else if (isset($ldapEntry['samaccountname'])) {
227 227
 			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
228 228
 		}
229 229
 
230 230
 		//homePath
231
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
231
+		if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
232 232
 			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
233
-			if(isset($ldapEntry[$attr])) {
233
+			if (isset($ldapEntry[$attr])) {
234 234
 				$this->access->cacheUserHome(
235 235
 					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
236 236
 			}
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
 		//memberOf groups
240 240
 		$cacheKey = 'getMemberOf'.$this->getUsername();
241 241
 		$groups = false;
242
-		if(isset($ldapEntry['memberof'])) {
242
+		if (isset($ldapEntry['memberof'])) {
243 243
 			$groups = $ldapEntry['memberof'];
244 244
 		}
245 245
 		$this->connection->writeToCache($cacheKey, $groups);
246 246
 
247 247
 		//Avatar
248 248
 		$attrs = array('jpegphoto', 'thumbnailphoto');
249
-		foreach ($attrs as $attr)  {
250
-			if(isset($ldapEntry[$attr])) {
249
+		foreach ($attrs as $attr) {
250
+			if (isset($ldapEntry[$attr])) {
251 251
 				$this->avatarImage = $ldapEntry[$attr][0];
252 252
 				// the call to the method that saves the avatar in the file
253 253
 				// system must be postponed after the login. It is to ensure
@@ -300,12 +300,12 @@  discard block
 block discarded – undo
300 300
 		if ($path !== '') {
301 301
 			//if attribute's value is an absolute path take this, otherwise append it to data dir
302 302
 			//check for / at the beginning or pattern c:\ resp. c:/
303
-			if(   '/' !== $path[0]
303
+			if ('/' !== $path[0]
304 304
 			   && !(3 < strlen($path) && ctype_alpha($path[0])
305 305
 			       && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
306 306
 			) {
307 307
 				$path = $this->config->getSystemValue('datadirectory',
308
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
308
+						\OC::$SERVERROOT.'/data').'/'.$path;
309 309
 			}
310 310
 			//we need it to store it in the DB as well in case a user gets
311 311
 			//deleted so we can clean up afterwards
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
 			return $path;
316 316
 		}
317 317
 
318
-		if(    !is_null($attr)
318
+		if (!is_null($attr)
319 319
 			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
320 320
 		) {
321 321
 			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
322
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
322
+			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername());
323 323
 		}
324 324
 
325 325
 		//false will apply default behaviour as defined and done by OC_User
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	public function getMemberOfGroups() {
331 331
 		$cacheKey = 'getMemberOf'.$this->getUsername();
332 332
 		$memberOfGroups = $this->connection->getFromCache($cacheKey);
333
-		if(!is_null($memberOfGroups)) {
333
+		if (!is_null($memberOfGroups)) {
334 334
 			return $memberOfGroups;
335 335
 		}
336 336
 		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
@@ -343,15 +343,15 @@  discard block
 block discarded – undo
343 343
 	 * @return string data (provided by LDAP) | false
344 344
 	 */
345 345
 	public function getAvatarImage() {
346
-		if(!is_null($this->avatarImage)) {
346
+		if (!is_null($this->avatarImage)) {
347 347
 			return $this->avatarImage;
348 348
 		}
349 349
 
350 350
 		$this->avatarImage = false;
351 351
 		$attributes = array('jpegPhoto', 'thumbnailPhoto');
352
-		foreach($attributes as $attribute) {
352
+		foreach ($attributes as $attribute) {
353 353
 			$result = $this->access->readAttribute($this->dn, $attribute);
354
-			if($result !== false && is_array($result) && isset($result[0])) {
354
+			if ($result !== false && is_array($result) && isset($result[0])) {
355 355
 				$this->avatarImage = $result[0];
356 356
 				break;
357 357
 			}
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 		$lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
389 389
 			self::USER_PREFKEY_LASTREFRESH, 0);
390 390
 
391
-		if((time() - intval($lastChecked)) < intval($this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) ) {
391
+		if ((time() - intval($lastChecked)) < intval($this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400))) {
392 392
 			return false;
393 393
 		}
394 394
 		return  true;
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 	 */
415 415
 	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
416 416
 		$displayName2 = strval($displayName2);
417
-		if($displayName2 !== '') {
418
-			$displayName .= ' (' . $displayName2 . ')';
417
+		if ($displayName2 !== '') {
418
+			$displayName .= ' ('.$displayName2.')';
419 419
 		}
420 420
 		$this->store('displayName', $displayName);
421 421
 		return $displayName;
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 * @return bool
438 438
 	 */
439 439
 	private function wasRefreshed($feature) {
440
-		if(isset($this->refreshedFeatures[$feature])) {
440
+		if (isset($this->refreshedFeatures[$feature])) {
441 441
 			return true;
442 442
 		}
443 443
 		$this->refreshedFeatures[$feature] = 1;
@@ -450,15 +450,15 @@  discard block
 block discarded – undo
450 450
 	 * @return null
451 451
 	 */
452 452
 	public function updateEmail($valueFromLDAP = null) {
453
-		if($this->wasRefreshed('email')) {
453
+		if ($this->wasRefreshed('email')) {
454 454
 			return;
455 455
 		}
456 456
 		$email = strval($valueFromLDAP);
457
-		if(is_null($valueFromLDAP)) {
457
+		if (is_null($valueFromLDAP)) {
458 458
 			$emailAttribute = $this->connection->ldapEmailAttribute;
459 459
 			if ($emailAttribute !== '') {
460 460
 				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
461
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
461
+				if (is_array($aEmail) && (count($aEmail) > 0)) {
462 462
 					$email = strval($aEmail[0]);
463 463
 				}
464 464
 			}
@@ -495,35 +495,35 @@  discard block
 block discarded – undo
495 495
 	 * @return null
496 496
 	 */
497 497
 	public function updateQuota($valueFromLDAP = null) {
498
-		if($this->wasRefreshed('quota')) {
498
+		if ($this->wasRefreshed('quota')) {
499 499
 			return;
500 500
 		}
501 501
 
502 502
 		$quotaAttribute = $this->connection->ldapQuotaAttribute;
503 503
 		$defaultQuota = $this->connection->ldapQuotaDefault;
504
-		if($quotaAttribute === '' && $defaultQuota === '') {
504
+		if ($quotaAttribute === '' && $defaultQuota === '') {
505 505
 			return;
506 506
 		}
507 507
 
508 508
 		$quota = false;
509
-		if(is_null($valueFromLDAP) && $quotaAttribute !== '') {
509
+		if (is_null($valueFromLDAP) && $quotaAttribute !== '') {
510 510
 			$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
511
-			if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
511
+			if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
512 512
 				$quota = $aQuota[0];
513
-			} else if(is_array($aQuota) && isset($aQuota[0])) {
514
-				$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', Util::DEBUG);
513
+			} else if (is_array($aQuota) && isset($aQuota[0])) {
514
+				$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', Util::DEBUG);
515 515
 			}
516 516
 		} else if ($this->verifyQuotaValue($valueFromLDAP)) {
517 517
 			$quota = $valueFromLDAP;
518 518
 		} else {
519
-			$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', Util::DEBUG);
519
+			$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', Util::DEBUG);
520 520
 		}
521 521
 
522 522
 		if ($quota === false && $this->verifyQuotaValue($defaultQuota)) {
523 523
 			// quota not found using the LDAP attribute (or not parseable). Try the default quota
524 524
 			$quota = $defaultQuota;
525
-		} else if($quota === false) {
526
-			$this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', Util::DEBUG);
525
+		} else if ($quota === false) {
526
+			$this->log->log('no suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', Util::DEBUG);
527 527
 			return;
528 528
 		}
529 529
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 		if ($targetUser instanceof IUser) {
532 532
 			$targetUser->setQuota($quota);
533 533
 		} else {
534
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', Util::INFO);
534
+			$this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', Util::INFO);
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,15 +555,15 @@  discard block
 block discarded – undo
555 555
 	 * @return bool
556 556
 	 */
557 557
 	public function updateAvatar($force = false) {
558
-		if(!$force && $this->wasRefreshed('avatar')) {
558
+		if (!$force && $this->wasRefreshed('avatar')) {
559 559
 			return false;
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 false;
565 565
 		}
566
-		if(!$this->image->loadFromBase64(base64_encode($avatarImage))) {
566
+		if (!$this->image->loadFromBase64(base64_encode($avatarImage))) {
567 567
 			return false;
568 568
 		}
569 569
 		return $this->setOwnCloudAvatar();
@@ -574,18 +574,18 @@  discard block
 block discarded – undo
574 574
 	 * @return bool
575 575
 	 */
576 576
 	private function setOwnCloudAvatar() {
577
-		if(!$this->image->valid()) {
577
+		if (!$this->image->valid()) {
578 578
 			$this->log->log('jpegPhoto data invalid for '.$this->dn, Util::ERROR);
579 579
 			return false;
580 580
 		}
581 581
 		//make sure it is a square and not bigger than 128x128
582 582
 		$size = min(array($this->image->width(), $this->image->height(), 128));
583
-		if(!$this->image->centerCrop($size)) {
583
+		if (!$this->image->centerCrop($size)) {
584 584
 			$this->log->log('croping image for avatar failed for '.$this->dn, Util::ERROR);
585 585
 			return false;
586 586
 		}
587 587
 
588
-		if(!$this->fs->isLoaded()) {
588
+		if (!$this->fs->isLoaded()) {
589 589
 			$this->fs->setup($this->uid);
590 590
 		}
591 591
 
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 			return true;
596 596
 		} catch (\Exception $e) {
597 597
 			\OC::$server->getLogger()->notice(
598
-				'Could not set avatar for ' . $this->dn	. ', because: ' . $e->getMessage(),
598
+				'Could not set avatar for '.$this->dn.', because: '.$e->getMessage(),
599 599
 				['app' => 'user_ldap']);
600 600
 		}
601 601
 		return false;
@@ -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=*', array($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=*', array($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.
apps/user_ldap/lib/User_LDAP.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 		}
104 104
 
105 105
 		$user = $this->access->userManager->get($uid);
106
-		if(!$user instanceof User) {
106
+		if (!$user instanceof User) {
107 107
 			return false;
108 108
 		}
109 109
 		$imageData = $user->getAvatarImage();
110
-		if($imageData === false) {
110
+		if ($imageData === false) {
111 111
 			return true;
112 112
 		}
113 113
 		return !$user->updateAvatar(true);
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 	public function loginName2UserName($loginName) {
123 123
 		$cacheKey = 'loginName2UserName-'.$loginName;
124 124
 		$username = $this->access->connection->getFromCache($cacheKey);
125
-		if(!is_null($username)) {
125
+		if (!is_null($username)) {
126 126
 			return $username;
127 127
 		}
128 128
 
129 129
 		try {
130 130
 			$ldapRecord = $this->getLDAPUserByLoginName($loginName);
131 131
 			$user = $this->access->userManager->get($ldapRecord['dn'][0]);
132
-			if($user instanceof OfflineUser) {
132
+			if ($user instanceof OfflineUser) {
133 133
 				// this path is not really possible, however get() is documented
134 134
 				// to return User or OfflineUser so we are very defensive here.
135 135
 				$this->access->connection->writeToCache($cacheKey, false);
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 		//find out dn of the user name
166 166
 		$attrs = $this->access->userManager->getAttributes();
167 167
 		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
168
-		if(count($users) < 1) {
169
-			throw new NotOnLDAP('No user available for the given login name on ' .
170
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
168
+		if (count($users) < 1) {
169
+			throw new NotOnLDAP('No user available for the given login name on '.
170
+				$this->access->connection->ldapHost.':'.$this->access->connection->ldapPort);
171 171
 		}
172 172
 		return $users[0];
173 173
 	}
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
 	public function checkPassword($uid, $password) {
183 183
 		try {
184 184
 			$ldapRecord = $this->getLDAPUserByLoginName($uid);
185
-		} catch(NotOnLDAP $e) {
186
-			if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
185
+		} catch (NotOnLDAP $e) {
186
+			if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
187 187
 				\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
188 188
 			}
189 189
 			return false;
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
 		$dn = $ldapRecord['dn'][0];
192 192
 		$user = $this->access->userManager->get($dn);
193 193
 
194
-		if(!$user instanceof User) {
194
+		if (!$user instanceof User) {
195 195
 			Util::writeLog('user_ldap',
196
-				'LDAP Login: Could not get user object for DN ' . $dn .
196
+				'LDAP Login: Could not get user object for DN '.$dn.
197 197
 				'. Maybe the LDAP entry has no set display name attribute?',
198 198
 				Util::WARN);
199 199
 			return false;
200 200
 		}
201
-		if($user->getUsername() !== false) {
201
+		if ($user->getUsername() !== false) {
202 202
 			//are the credentials OK?
203
-			if(!$this->access->areCredentialsValid($dn, $password)) {
203
+			if (!$this->access->areCredentialsValid($dn, $password)) {
204 204
 				return false;
205 205
 			}
206 206
 
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 
228 228
 		$user = $this->access->userManager->get($uid);
229 229
 
230
-		if(!$user instanceof User) {
231
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
230
+		if (!$user instanceof User) {
231
+			throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid.
232 232
 				'. Maybe the LDAP entry has no set display name attribute?');
233 233
 		}
234
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
234
+		if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
235 235
 			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
236 236
 			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
237 237
 			if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
@@ -263,18 +263,18 @@  discard block
 block discarded – undo
263 263
 
264 264
 		//check if users are cached, if so return
265 265
 		$ldap_users = $this->access->connection->getFromCache($cachekey);
266
-		if(!is_null($ldap_users)) {
266
+		if (!is_null($ldap_users)) {
267 267
 			return $ldap_users;
268 268
 		}
269 269
 
270 270
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
271 271
 		// error. With a limit of 0, we get 0 results. So we pass null.
272
-		if($limit <= 0) {
272
+		if ($limit <= 0) {
273 273
 			$limit = null;
274 274
 		}
275 275
 		$filter = $this->access->combineFilterWithAnd(array(
276 276
 			$this->access->connection->ldapUserFilter,
277
-			$this->access->connection->ldapUserDisplayName . '=*',
277
+			$this->access->connection->ldapUserDisplayName.'=*',
278 278
 			$this->access->getFilterPartForUserSearch($search)
279 279
 		));
280 280
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 			$this->access->userManager->getAttributes(true),
288 288
 			$limit, $offset);
289 289
 		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
290
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
290
+		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG);
291 291
 
292 292
 		$this->access->connection->writeToCache($cachekey, $ldap_users);
293 293
 		return $ldap_users;
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
 	 * @throws \OC\ServerNotAvailableException
304 304
 	 */
305 305
 	public function userExistsOnLDAP($user) {
306
-		if(is_string($user)) {
306
+		if (is_string($user)) {
307 307
 			$user = $this->access->userManager->get($user);
308 308
 		}
309
-		if(is_null($user)) {
309
+		if (is_null($user)) {
310 310
 			return false;
311 311
 		}
312 312
 
313 313
 		$dn = $user->getDN();
314 314
 		//check if user really still exists by reading its entry
315
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
315
+		if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
316 316
 			$lcr = $this->access->connection->getConnectionResource();
317
-			if(is_null($lcr)) {
318
-				throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
317
+			if (is_null($lcr)) {
318
+				throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost);
319 319
 			}
320 320
 
321 321
 			try {
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 			}
338 338
 		}
339 339
 
340
-		if($user instanceof OfflineUser) {
340
+		if ($user instanceof OfflineUser) {
341 341
 			$user->unmark();
342 342
 		}
343 343
 
@@ -352,18 +352,18 @@  discard block
 block discarded – undo
352 352
 	 */
353 353
 	public function userExists($uid) {
354 354
 		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
355
-		if(!is_null($userExists)) {
356
-			return (bool)$userExists;
355
+		if (!is_null($userExists)) {
356
+			return (bool) $userExists;
357 357
 		}
358 358
 		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
359 359
 		$user = $this->access->userManager->get($uid);
360 360
 
361
-		if(is_null($user)) {
361
+		if (is_null($user)) {
362 362
 			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
363 363
 				$this->access->connection->ldapHost, Util::DEBUG);
364 364
 			$this->access->connection->writeToCache('userExists'.$uid, false);
365 365
 			return false;
366
-		} else if($user instanceof OfflineUser) {
366
+		} else if ($user instanceof OfflineUser) {
367 367
 			//express check for users marked as deleted. Returning true is
368 368
 			//necessary for cleanup
369 369
 			return true;
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 
372 372
 		$result = $this->userExistsOnLDAP($user);
373 373
 		$this->access->connection->writeToCache('userExists'.$uid, $result);
374
-		if($result === true) {
374
+		if ($result === true) {
375 375
 			$user->update();
376 376
 		}
377 377
 		return $result;
@@ -389,13 +389,13 @@  discard block
 block discarded – undo
389 389
 		}
390 390
 
391 391
 		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
392
-		if(intval($marked) === 0) {
392
+		if (intval($marked) === 0) {
393 393
 			\OC::$server->getLogger()->notice(
394
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
394
+				'User '.$uid.' is not marked as deleted, not cleaning up.',
395 395
 				array('app' => 'user_ldap'));
396 396
 			return false;
397 397
 		}
398
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
398
+		\OC::$server->getLogger()->info('Cleaning up after user '.$uid,
399 399
 			array('app' => 'user_ldap'));
400 400
 
401 401
 		$this->access->getUserMapper()->unmap($uid);
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 	 */
414 414
 	public function getHome($uid) {
415 415
 		// user Exists check required as it is not done in user proxy!
416
-		if(!$this->userExists($uid)) {
416
+		if (!$this->userExists($uid)) {
417 417
 			return false;
418 418
 		}
419 419
 
@@ -423,22 +423,22 @@  discard block
 block discarded – undo
423 423
 
424 424
 		$cacheKey = 'getHome'.$uid;
425 425
 		$path = $this->access->connection->getFromCache($cacheKey);
426
-		if(!is_null($path)) {
426
+		if (!is_null($path)) {
427 427
 			return $path;
428 428
 		}
429 429
 
430 430
 		// early return path if it is a deleted user
431 431
 		$user = $this->access->userManager->get($uid);
432
-		if($user instanceof OfflineUser) {
433
-			if($this->currentUserInDeletionProcess !== null
432
+		if ($user instanceof OfflineUser) {
433
+			if ($this->currentUserInDeletionProcess !== null
434 434
 				&& $this->currentUserInDeletionProcess === $user->getOCName()
435 435
 			) {
436 436
 				return $user->getHomePath();
437 437
 			} else {
438
-				throw new NoUserException($uid . ' is not a valid user anymore');
438
+				throw new NoUserException($uid.' is not a valid user anymore');
439 439
 			}
440 440
 		} else if ($user === null) {
441
-			throw new NoUserException($uid . ' is not a valid user anymore');
441
+			throw new NoUserException($uid.' is not a valid user anymore');
442 442
 		}
443 443
 
444 444
 		$path = $user->getHomePath();
@@ -457,12 +457,12 @@  discard block
 block discarded – undo
457 457
 			return $this->userPluginManager->getDisplayName($uid);
458 458
 		}
459 459
 
460
-		if(!$this->userExists($uid)) {
460
+		if (!$this->userExists($uid)) {
461 461
 			return false;
462 462
 		}
463 463
 
464 464
 		$cacheKey = 'getDisplayName'.$uid;
465
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
465
+		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
466 466
 			return $displayName;
467 467
 		}
468 468
 
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
 			$this->access->username2dn($uid),
480 480
 			$this->access->connection->ldapUserDisplayName);
481 481
 
482
-		if($displayName && (count($displayName) > 0)) {
482
+		if ($displayName && (count($displayName) > 0)) {
483 483
 			$displayName = $displayName[0];
484 484
 
485
-			if (is_array($displayName2)){
485
+			if (is_array($displayName2)) {
486 486
 				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
487 487
 			}
488 488
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 	 */
525 525
 	public function getDisplayNames($search = '', $limit = null, $offset = null) {
526 526
 		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
527
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
527
+		if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
528 528
 			return $displayNames;
529 529
 		}
530 530
 
@@ -546,12 +546,12 @@  discard block
 block discarded – undo
546 546
 	* compared with \OC\User\Backend::CREATE_USER etc.
547 547
 	*/
548 548
 	public function implementsActions($actions) {
549
-		return (bool)((Backend::CHECK_PASSWORD
549
+		return (bool) ((Backend::CHECK_PASSWORD
550 550
 			| Backend::GET_HOME
551 551
 			| Backend::GET_DISPLAYNAME
552 552
 			| Backend::PROVIDE_AVATAR
553 553
 			| Backend::COUNT_USERS
554
-			| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)
554
+			| ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)
555 555
 			| $this->userPluginManager->getImplementedActions())
556 556
 			& $actions);
557 557
 	}
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 
576 576
 		$filter = $this->access->getFilterForUserCount();
577 577
 		$cacheKey = 'countUsers-'.$filter;
578
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
578
+		if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
579 579
 			return $entries;
580 580
 		}
581 581
 		$entries = $this->access->countUsers($filter);
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 	 * Backend name to be shown in user management
588 588
 	 * @return string the name of the backend to be shown
589 589
 	 */
590
-	public function getBackendName(){
590
+	public function getBackendName() {
591 591
 		return 'LDAP';
592 592
 	}
593 593
 	
Please login to merge, or discard this patch.