Completed
Push — stable13 ( ff3b13...a4e989 )
by Roeland
16:47
created
settings/Hooks.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -38,176 +38,176 @@
 block discarded – undo
38 38
 
39 39
 class Hooks {
40 40
 
41
-	/** @var IActivityManager */
42
-	protected $activityManager;
43
-	/** @var IUserManager */
44
-	protected $userManager;
45
-	/** @var IUserSession */
46
-	protected $userSession;
47
-	/** @var IURLGenerator */
48
-	protected $urlGenerator;
49
-	/** @var IMailer */
50
-	protected $mailer;
51
-	/** @var IConfig */
52
-	protected $config;
53
-	/** @var IFactory */
54
-	protected $languageFactory;
55
-	/** @var IL10N */
56
-	protected $l;
57
-
58
-	public function __construct(IActivityManager $activityManager,
59
-								IUserManager $userManager,
60
-								IUserSession $userSession,
61
-								IURLGenerator $urlGenerator,
62
-								IMailer $mailer,
63
-								IConfig $config,
64
-								IFactory $languageFactory,
65
-								IL10N $l) {
66
-		$this->activityManager = $activityManager;
67
-		$this->userManager = $userManager;
68
-		$this->userSession = $userSession;
69
-		$this->urlGenerator = $urlGenerator;
70
-		$this->mailer = $mailer;
71
-		$this->config = $config;
72
-		$this->languageFactory = $languageFactory;
73
-		$this->l = $l;
74
-	}
75
-
76
-	/**
77
-	 * @param string $uid
78
-	 * @throws \InvalidArgumentException
79
-	 * @throws \BadMethodCallException
80
-	 * @throws \Exception
81
-	 */
82
-	public function onChangePassword($uid) {
83
-		$user = $this->userManager->get($uid);
84
-
85
-		if (!$user instanceof IUser || $user->getLastLogin() === 0) {
86
-			// User didn't login, so don't create activities and emails.
87
-			return;
88
-		}
89
-
90
-		$event = $this->activityManager->generateEvent();
91
-		$event->setApp('settings')
92
-			->setType('personal_settings')
93
-			->setAffectedUser($user->getUID());
94
-
95
-		$instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
96
-
97
-		$actor = $this->userSession->getUser();
98
-		if ($actor instanceof IUser) {
99
-			if ($actor->getUID() !== $user->getUID()) {
100
-				$this->l = $this->languageFactory->get(
101
-					'settings',
102
-					$this->config->getUserValue(
103
-						$user->getUID(), 'core', 'lang',
104
-						$this->config->getSystemValue('default_language', 'en')
105
-					)
106
-				);
107
-
108
-				$text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]);
109
-				$event->setAuthor($actor->getUID())
110
-					->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]);
111
-			} else {
112
-				$text = $this->l->t('Your password on %s was changed.', [$instanceUrl]);
113
-				$event->setAuthor($actor->getUID())
114
-					->setSubject(Provider::PASSWORD_CHANGED_SELF);
115
-			}
116
-		} else {
117
-			$text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
118
-			$event->setSubject(Provider::PASSWORD_RESET);
119
-		}
120
-
121
-		$this->activityManager->publish($event);
122
-
123
-		if ($user->getEMailAddress() !== null) {
124
-			$template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [
125
-				'displayname' => $user->getDisplayName(),
126
-				'emailAddress' => $user->getEMailAddress(),
127
-				'instanceUrl' => $instanceUrl,
128
-			]);
129
-
130
-			$template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
131
-			$template->addHeader();
132
-			$template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false);
133
-			$template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.'));
134
-			$template->addFooter();
135
-
136
-
137
-			$message = $this->mailer->createMessage();
138
-			$message->setTo([$user->getEMailAddress() => $user->getDisplayName()]);
139
-			$message->useTemplate($template);
140
-			$this->mailer->send($message);
141
-		}
142
-	}
143
-
144
-	/**
145
-	 * @param IUser $user
146
-	 * @param string|null $oldMailAddress
147
-	 * @throws \InvalidArgumentException
148
-	 * @throws \BadMethodCallException
149
-	 */
150
-	public function onChangeEmail(IUser $user, $oldMailAddress) {
151
-
152
-		if ($oldMailAddress === $user->getEMailAddress() ||
153
-			$user->getLastLogin() === 0) {
154
-			// Email didn't really change or user didn't login,
155
-			// so don't create activities and emails.
156
-			return;
157
-		}
158
-
159
-		$event = $this->activityManager->generateEvent();
160
-		$event->setApp('settings')
161
-			->setType('personal_settings')
162
-			->setAffectedUser($user->getUID());
163
-
164
-		$instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
165
-
166
-		$actor = $this->userSession->getUser();
167
-		if ($actor instanceof IUser) {
168
-			$subject = Provider::EMAIL_CHANGED_SELF;
169
-			if ($actor->getUID() !== $user->getUID()) {
170
-				$this->l = $this->languageFactory->get(
171
-					'settings',
172
-					$this->config->getUserValue(
173
-						$user->getUID(), 'core', 'lang',
174
-						$this->config->getSystemValue('default_language', 'en')
175
-					)
176
-				);
177
-				$subject = Provider::EMAIL_CHANGED;
178
-			}
179
-			$text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]);
180
-			$event->setAuthor($actor->getUID())
181
-				->setSubject($subject);
182
-		} else {
183
-			$text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]);
184
-			$event->setSubject(Provider::EMAIL_CHANGED);
185
-		}
186
-		$this->activityManager->publish($event);
187
-
188
-
189
-		if ($oldMailAddress !== null) {
190
-			$template = $this->mailer->createEMailTemplate('settings.EmailChanged', [
191
-				'displayname' => $user->getDisplayName(),
192
-				'newEMailAddress' => $user->getEMailAddress(),
193
-				'oldEMailAddress' => $oldMailAddress,
194
-				'instanceUrl' => $instanceUrl,
195
-			]);
196
-
197
-			$template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
198
-			$template->addHeader();
199
-			$template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false);
200
-			$template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.'));
201
-			if ($user->getEMailAddress()) {
202
-				$template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()]));
203
-			}
204
-			$template->addFooter();
205
-
206
-
207
-			$message = $this->mailer->createMessage();
208
-			$message->setTo([$oldMailAddress => $user->getDisplayName()]);
209
-			$message->useTemplate($template);
210
-			$this->mailer->send($message);
211
-		}
212
-	}
41
+    /** @var IActivityManager */
42
+    protected $activityManager;
43
+    /** @var IUserManager */
44
+    protected $userManager;
45
+    /** @var IUserSession */
46
+    protected $userSession;
47
+    /** @var IURLGenerator */
48
+    protected $urlGenerator;
49
+    /** @var IMailer */
50
+    protected $mailer;
51
+    /** @var IConfig */
52
+    protected $config;
53
+    /** @var IFactory */
54
+    protected $languageFactory;
55
+    /** @var IL10N */
56
+    protected $l;
57
+
58
+    public function __construct(IActivityManager $activityManager,
59
+                                IUserManager $userManager,
60
+                                IUserSession $userSession,
61
+                                IURLGenerator $urlGenerator,
62
+                                IMailer $mailer,
63
+                                IConfig $config,
64
+                                IFactory $languageFactory,
65
+                                IL10N $l) {
66
+        $this->activityManager = $activityManager;
67
+        $this->userManager = $userManager;
68
+        $this->userSession = $userSession;
69
+        $this->urlGenerator = $urlGenerator;
70
+        $this->mailer = $mailer;
71
+        $this->config = $config;
72
+        $this->languageFactory = $languageFactory;
73
+        $this->l = $l;
74
+    }
75
+
76
+    /**
77
+     * @param string $uid
78
+     * @throws \InvalidArgumentException
79
+     * @throws \BadMethodCallException
80
+     * @throws \Exception
81
+     */
82
+    public function onChangePassword($uid) {
83
+        $user = $this->userManager->get($uid);
84
+
85
+        if (!$user instanceof IUser || $user->getLastLogin() === 0) {
86
+            // User didn't login, so don't create activities and emails.
87
+            return;
88
+        }
89
+
90
+        $event = $this->activityManager->generateEvent();
91
+        $event->setApp('settings')
92
+            ->setType('personal_settings')
93
+            ->setAffectedUser($user->getUID());
94
+
95
+        $instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
96
+
97
+        $actor = $this->userSession->getUser();
98
+        if ($actor instanceof IUser) {
99
+            if ($actor->getUID() !== $user->getUID()) {
100
+                $this->l = $this->languageFactory->get(
101
+                    'settings',
102
+                    $this->config->getUserValue(
103
+                        $user->getUID(), 'core', 'lang',
104
+                        $this->config->getSystemValue('default_language', 'en')
105
+                    )
106
+                );
107
+
108
+                $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]);
109
+                $event->setAuthor($actor->getUID())
110
+                    ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]);
111
+            } else {
112
+                $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]);
113
+                $event->setAuthor($actor->getUID())
114
+                    ->setSubject(Provider::PASSWORD_CHANGED_SELF);
115
+            }
116
+        } else {
117
+            $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
118
+            $event->setSubject(Provider::PASSWORD_RESET);
119
+        }
120
+
121
+        $this->activityManager->publish($event);
122
+
123
+        if ($user->getEMailAddress() !== null) {
124
+            $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [
125
+                'displayname' => $user->getDisplayName(),
126
+                'emailAddress' => $user->getEMailAddress(),
127
+                'instanceUrl' => $instanceUrl,
128
+            ]);
129
+
130
+            $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
131
+            $template->addHeader();
132
+            $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false);
133
+            $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.'));
134
+            $template->addFooter();
135
+
136
+
137
+            $message = $this->mailer->createMessage();
138
+            $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]);
139
+            $message->useTemplate($template);
140
+            $this->mailer->send($message);
141
+        }
142
+    }
143
+
144
+    /**
145
+     * @param IUser $user
146
+     * @param string|null $oldMailAddress
147
+     * @throws \InvalidArgumentException
148
+     * @throws \BadMethodCallException
149
+     */
150
+    public function onChangeEmail(IUser $user, $oldMailAddress) {
151
+
152
+        if ($oldMailAddress === $user->getEMailAddress() ||
153
+            $user->getLastLogin() === 0) {
154
+            // Email didn't really change or user didn't login,
155
+            // so don't create activities and emails.
156
+            return;
157
+        }
158
+
159
+        $event = $this->activityManager->generateEvent();
160
+        $event->setApp('settings')
161
+            ->setType('personal_settings')
162
+            ->setAffectedUser($user->getUID());
163
+
164
+        $instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
165
+
166
+        $actor = $this->userSession->getUser();
167
+        if ($actor instanceof IUser) {
168
+            $subject = Provider::EMAIL_CHANGED_SELF;
169
+            if ($actor->getUID() !== $user->getUID()) {
170
+                $this->l = $this->languageFactory->get(
171
+                    'settings',
172
+                    $this->config->getUserValue(
173
+                        $user->getUID(), 'core', 'lang',
174
+                        $this->config->getSystemValue('default_language', 'en')
175
+                    )
176
+                );
177
+                $subject = Provider::EMAIL_CHANGED;
178
+            }
179
+            $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]);
180
+            $event->setAuthor($actor->getUID())
181
+                ->setSubject($subject);
182
+        } else {
183
+            $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]);
184
+            $event->setSubject(Provider::EMAIL_CHANGED);
185
+        }
186
+        $this->activityManager->publish($event);
187
+
188
+
189
+        if ($oldMailAddress !== null) {
190
+            $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [
191
+                'displayname' => $user->getDisplayName(),
192
+                'newEMailAddress' => $user->getEMailAddress(),
193
+                'oldEMailAddress' => $oldMailAddress,
194
+                'instanceUrl' => $instanceUrl,
195
+            ]);
196
+
197
+            $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
198
+            $template->addHeader();
199
+            $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false);
200
+            $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.'));
201
+            if ($user->getEMailAddress()) {
202
+                $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()]));
203
+            }
204
+            $template->addFooter();
205
+
206
+
207
+            $message = $this->mailer->createMessage();
208
+            $message->setTo([$oldMailAddress => $user->getDisplayName()]);
209
+            $message->useTemplate($template);
210
+            $this->mailer->send($message);
211
+        }
212
+    }
213 213
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_LDAP.php 2 patches
Indentation   +566 added lines, -566 removed lines patch added patch discarded remove patch
@@ -51,574 +51,574 @@
 block discarded – undo
51 51
 use OCP\Util;
52 52
 
53 53
 class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
54
-	/** @var \OCP\IConfig */
55
-	protected $ocConfig;
56
-
57
-	/** @var INotificationManager */
58
-	protected $notificationManager;
59
-
60
-	/** @var string */
61
-	protected $currentUserInDeletionProcess;
62
-
63
-	/** @var UserPluginManager */
64
-	protected $userPluginManager;
65
-
66
-	/**
67
-	 * @param Access $access
68
-	 * @param \OCP\IConfig $ocConfig
69
-	 * @param \OCP\Notification\IManager $notificationManager
70
-	 * @param IUserSession $userSession
71
-	 */
72
-	public function __construct(Access $access, IConfig $ocConfig, INotificationManager $notificationManager, IUserSession $userSession, UserPluginManager $userPluginManager) {
73
-		parent::__construct($access);
74
-		$this->ocConfig = $ocConfig;
75
-		$this->notificationManager = $notificationManager;
76
-		$this->userPluginManager = $userPluginManager;
77
-		$this->registerHooks($userSession);
78
-	}
79
-
80
-	protected function registerHooks(IUserSession $userSession) {
81
-		$userSession->listen('\OC\User', 'preDelete', [$this, 'preDeleteUser']);
82
-		$userSession->listen('\OC\User', 'postDelete', [$this, 'postDeleteUser']);
83
-	}
84
-
85
-	public function preDeleteUser(IUser $user) {
86
-		$this->currentUserInDeletionProcess = $user->getUID();
87
-	}
88
-
89
-	public function postDeleteUser() {
90
-		$this->currentUserInDeletionProcess = null;
91
-	}
92
-
93
-	/**
94
-	 * checks whether the user is allowed to change his avatar in Nextcloud
95
-	 *
96
-	 * @param string $uid the Nextcloud user name
97
-	 * @return boolean either the user can or cannot
98
-	 * @throws \Exception
99
-	 */
100
-	public function canChangeAvatar($uid) {
101
-		if ($this->userPluginManager->implementsActions(Backend::PROVIDE_AVATAR)) {
102
-			return $this->userPluginManager->canChangeAvatar($uid);
103
-		}
104
-
105
-		if(!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
106
-			return true;
107
-		}
108
-
109
-		$user = $this->access->userManager->get($uid);
110
-		if(!$user instanceof User) {
111
-			return false;
112
-		}
113
-		$imageData = $user->getAvatarImage();
114
-		if($imageData === false) {
115
-			return true;
116
-		}
117
-		return !$user->updateAvatar(true);
118
-	}
119
-
120
-	/**
121
-	 * returns the username for the given login name, if available
122
-	 *
123
-	 * @param string $loginName
124
-	 * @return string|false
125
-	 */
126
-	public function loginName2UserName($loginName) {
127
-		$cacheKey = 'loginName2UserName-'.$loginName;
128
-		$username = $this->access->connection->getFromCache($cacheKey);
129
-		if(!is_null($username)) {
130
-			return $username;
131
-		}
132
-
133
-		try {
134
-			$ldapRecord = $this->getLDAPUserByLoginName($loginName);
135
-			$user = $this->access->userManager->get($ldapRecord['dn'][0]);
136
-			if($user instanceof OfflineUser) {
137
-				// this path is not really possible, however get() is documented
138
-				// to return User or OfflineUser so we are very defensive here.
139
-				$this->access->connection->writeToCache($cacheKey, false);
140
-				return false;
141
-			}
142
-			$username = $user->getUsername();
143
-			$this->access->connection->writeToCache($cacheKey, $username);
144
-			return $username;
145
-		} catch (NotOnLDAP $e) {
146
-			$this->access->connection->writeToCache($cacheKey, false);
147
-			return false;
148
-		}
149
-	}
54
+    /** @var \OCP\IConfig */
55
+    protected $ocConfig;
56
+
57
+    /** @var INotificationManager */
58
+    protected $notificationManager;
59
+
60
+    /** @var string */
61
+    protected $currentUserInDeletionProcess;
62
+
63
+    /** @var UserPluginManager */
64
+    protected $userPluginManager;
65
+
66
+    /**
67
+     * @param Access $access
68
+     * @param \OCP\IConfig $ocConfig
69
+     * @param \OCP\Notification\IManager $notificationManager
70
+     * @param IUserSession $userSession
71
+     */
72
+    public function __construct(Access $access, IConfig $ocConfig, INotificationManager $notificationManager, IUserSession $userSession, UserPluginManager $userPluginManager) {
73
+        parent::__construct($access);
74
+        $this->ocConfig = $ocConfig;
75
+        $this->notificationManager = $notificationManager;
76
+        $this->userPluginManager = $userPluginManager;
77
+        $this->registerHooks($userSession);
78
+    }
79
+
80
+    protected function registerHooks(IUserSession $userSession) {
81
+        $userSession->listen('\OC\User', 'preDelete', [$this, 'preDeleteUser']);
82
+        $userSession->listen('\OC\User', 'postDelete', [$this, 'postDeleteUser']);
83
+    }
84
+
85
+    public function preDeleteUser(IUser $user) {
86
+        $this->currentUserInDeletionProcess = $user->getUID();
87
+    }
88
+
89
+    public function postDeleteUser() {
90
+        $this->currentUserInDeletionProcess = null;
91
+    }
92
+
93
+    /**
94
+     * checks whether the user is allowed to change his avatar in Nextcloud
95
+     *
96
+     * @param string $uid the Nextcloud user name
97
+     * @return boolean either the user can or cannot
98
+     * @throws \Exception
99
+     */
100
+    public function canChangeAvatar($uid) {
101
+        if ($this->userPluginManager->implementsActions(Backend::PROVIDE_AVATAR)) {
102
+            return $this->userPluginManager->canChangeAvatar($uid);
103
+        }
104
+
105
+        if(!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
106
+            return true;
107
+        }
108
+
109
+        $user = $this->access->userManager->get($uid);
110
+        if(!$user instanceof User) {
111
+            return false;
112
+        }
113
+        $imageData = $user->getAvatarImage();
114
+        if($imageData === false) {
115
+            return true;
116
+        }
117
+        return !$user->updateAvatar(true);
118
+    }
119
+
120
+    /**
121
+     * returns the username for the given login name, if available
122
+     *
123
+     * @param string $loginName
124
+     * @return string|false
125
+     */
126
+    public function loginName2UserName($loginName) {
127
+        $cacheKey = 'loginName2UserName-'.$loginName;
128
+        $username = $this->access->connection->getFromCache($cacheKey);
129
+        if(!is_null($username)) {
130
+            return $username;
131
+        }
132
+
133
+        try {
134
+            $ldapRecord = $this->getLDAPUserByLoginName($loginName);
135
+            $user = $this->access->userManager->get($ldapRecord['dn'][0]);
136
+            if($user instanceof OfflineUser) {
137
+                // this path is not really possible, however get() is documented
138
+                // to return User or OfflineUser so we are very defensive here.
139
+                $this->access->connection->writeToCache($cacheKey, false);
140
+                return false;
141
+            }
142
+            $username = $user->getUsername();
143
+            $this->access->connection->writeToCache($cacheKey, $username);
144
+            return $username;
145
+        } catch (NotOnLDAP $e) {
146
+            $this->access->connection->writeToCache($cacheKey, false);
147
+            return false;
148
+        }
149
+    }
150 150
 	
151
-	/**
152
-	 * returns the username for the given LDAP DN, if available
153
-	 *
154
-	 * @param string $dn
155
-	 * @return string|false with the username
156
-	 */
157
-	public function dn2UserName($dn) {
158
-		return $this->access->dn2username($dn);
159
-	}
160
-
161
-	/**
162
-	 * returns an LDAP record based on a given login name
163
-	 *
164
-	 * @param string $loginName
165
-	 * @return array
166
-	 * @throws NotOnLDAP
167
-	 */
168
-	public function getLDAPUserByLoginName($loginName) {
169
-		//find out dn of the user name
170
-		$attrs = $this->access->userManager->getAttributes();
171
-		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
172
-		if(count($users) < 1) {
173
-			throw new NotOnLDAP('No user available for the given login name on ' .
174
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
175
-		}
176
-		return $users[0];
177
-	}
178
-
179
-	/**
180
-	 * Check if the password is correct without logging in the user
181
-	 *
182
-	 * @param string $uid The username
183
-	 * @param string $password The password
184
-	 * @return false|string
185
-	 */
186
-	public function checkPassword($uid, $password) {
187
-		try {
188
-			$ldapRecord = $this->getLDAPUserByLoginName($uid);
189
-		} catch(NotOnLDAP $e) {
190
-			if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
191
-				\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
192
-			}
193
-			return false;
194
-		}
195
-		$dn = $ldapRecord['dn'][0];
196
-		$user = $this->access->userManager->get($dn);
197
-
198
-		if(!$user instanceof User) {
199
-			Util::writeLog('user_ldap',
200
-				'LDAP Login: Could not get user object for DN ' . $dn .
201
-				'. Maybe the LDAP entry has no set display name attribute?',
202
-				Util::WARN);
203
-			return false;
204
-		}
205
-		if($user->getUsername() !== false) {
206
-			//are the credentials OK?
207
-			if(!$this->access->areCredentialsValid($dn, $password)) {
208
-				return false;
209
-			}
210
-
211
-			$this->access->cacheUserExists($user->getUsername());
212
-			$user->processAttributes($ldapRecord);
213
-			$user->markLogin();
214
-
215
-			return $user->getUsername();
216
-		}
217
-
218
-		return false;
219
-	}
220
-
221
-	/**
222
-	 * Set password
223
-	 * @param string $uid The username
224
-	 * @param string $password The new password
225
-	 * @return bool
226
-	 */
227
-	public function setPassword($uid, $password) {
228
-		if ($this->userPluginManager->implementsActions(Backend::SET_PASSWORD)) {
229
-			return $this->userPluginManager->setPassword($uid, $password);
230
-		}
231
-
232
-		$user = $this->access->userManager->get($uid);
233
-
234
-		if(!$user instanceof User) {
235
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
236
-				'. Maybe the LDAP entry has no set display name attribute?');
237
-		}
238
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
239
-			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
240
-			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
241
-			if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
242
-				//remove last password expiry warning if any
243
-				$notification = $this->notificationManager->createNotification();
244
-				$notification->setApp('user_ldap')
245
-					->setUser($uid)
246
-					->setObject('pwd_exp_warn', $uid)
247
-				;
248
-				$this->notificationManager->markProcessed($notification);
249
-			}
250
-			return true;
251
-		}
252
-
253
-		return false;
254
-	}
255
-
256
-	/**
257
-	 * Get a list of all users
258
-	 *
259
-	 * @param string $search
260
-	 * @param integer $limit
261
-	 * @param integer $offset
262
-	 * @return string[] an array of all uids
263
-	 */
264
-	public function getUsers($search = '', $limit = 10, $offset = 0) {
265
-		$search = $this->access->escapeFilterPart($search, true);
266
-		$cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
267
-
268
-		//check if users are cached, if so return
269
-		$ldap_users = $this->access->connection->getFromCache($cachekey);
270
-		if(!is_null($ldap_users)) {
271
-			return $ldap_users;
272
-		}
273
-
274
-		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
275
-		// error. With a limit of 0, we get 0 results. So we pass null.
276
-		if($limit <= 0) {
277
-			$limit = null;
278
-		}
279
-		$filter = $this->access->combineFilterWithAnd(array(
280
-			$this->access->connection->ldapUserFilter,
281
-			$this->access->connection->ldapUserDisplayName . '=*',
282
-			$this->access->getFilterPartForUserSearch($search)
283
-		));
284
-
285
-		Util::writeLog('user_ldap',
286
-			'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
287
-			Util::DEBUG);
288
-		//do the search and translate results to Nextcloud names
289
-		$ldap_users = $this->access->fetchListOfUsers(
290
-			$filter,
291
-			$this->access->userManager->getAttributes(true),
292
-			$limit, $offset);
293
-		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
294
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
295
-
296
-		$this->access->connection->writeToCache($cachekey, $ldap_users);
297
-		return $ldap_users;
298
-	}
299
-
300
-	/**
301
-	 * checks whether a user is still available on LDAP
302
-	 *
303
-	 * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
304
-	 * name or an instance of that user
305
-	 * @return bool
306
-	 * @throws \Exception
307
-	 * @throws \OC\ServerNotAvailableException
308
-	 */
309
-	public function userExistsOnLDAP($user) {
310
-		if(is_string($user)) {
311
-			$user = $this->access->userManager->get($user);
312
-		}
313
-		if(is_null($user)) {
314
-			return false;
315
-		}
316
-
317
-		$dn = $user->getDN();
318
-		//check if user really still exists by reading its entry
319
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
320
-			try {
321
-				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
322
-				if (!$uuid) {
323
-					return false;
324
-				}
325
-				$newDn = $this->access->getUserDnByUuid($uuid);
326
-				//check if renamed user is still valid by reapplying the ldap filter
327
-				if ($newDn === $dn || !is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
328
-					return false;
329
-				}
330
-				$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
331
-				return true;
332
-			} catch (ServerNotAvailableException $e) {
333
-				throw $e;
334
-			} catch (\Exception $e) {
335
-				return false;
336
-			}
337
-		}
338
-
339
-		if($user instanceof OfflineUser) {
340
-			$user->unmark();
341
-		}
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * check if a user exists
348
-	 * @param string $uid the username
349
-	 * @return boolean
350
-	 * @throws \Exception when connection could not be established
351
-	 */
352
-	public function userExists($uid) {
353
-		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
354
-		if(!is_null($userExists)) {
355
-			return (bool)$userExists;
356
-		}
357
-		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
358
-		$user = $this->access->userManager->get($uid);
359
-
360
-		if(is_null($user)) {
361
-			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
362
-				$this->access->connection->ldapHost, Util::DEBUG);
363
-			$this->access->connection->writeToCache('userExists'.$uid, false);
364
-			return false;
365
-		} else if($user instanceof OfflineUser) {
366
-			//express check for users marked as deleted. Returning true is
367
-			//necessary for cleanup
368
-			return true;
369
-		}
370
-
371
-		$result = $this->userExistsOnLDAP($user);
372
-		$this->access->connection->writeToCache('userExists'.$uid, $result);
373
-		return $result;
374
-	}
375
-
376
-	/**
377
-	* returns whether a user was deleted in LDAP
378
-	*
379
-	* @param string $uid The username of the user to delete
380
-	* @return bool
381
-	*/
382
-	public function deleteUser($uid) {
383
-		if ($this->userPluginManager->canDeleteUser()) {
384
-			return $this->userPluginManager->deleteUser($uid);
385
-		}
386
-
387
-		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
388
-		if(intval($marked) === 0) {
389
-			\OC::$server->getLogger()->notice(
390
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
391
-				array('app' => 'user_ldap'));
392
-			return false;
393
-		}
394
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
395
-			array('app' => 'user_ldap'));
396
-
397
-		$this->access->getUserMapper()->unmap($uid);
398
-		$this->access->userManager->invalidate($uid);
399
-		return true;
400
-	}
401
-
402
-	/**
403
-	 * get the user's home directory
404
-	 *
405
-	 * @param string $uid the username
406
-	 * @return bool|string
407
-	 * @throws NoUserException
408
-	 * @throws \Exception
409
-	 */
410
-	public function getHome($uid) {
411
-		// user Exists check required as it is not done in user proxy!
412
-		if(!$this->userExists($uid)) {
413
-			return false;
414
-		}
415
-
416
-		if ($this->userPluginManager->implementsActions(Backend::GET_HOME)) {
417
-			return $this->userPluginManager->getHome($uid);
418
-		}
419
-
420
-		$cacheKey = 'getHome'.$uid;
421
-		$path = $this->access->connection->getFromCache($cacheKey);
422
-		if(!is_null($path)) {
423
-			return $path;
424
-		}
425
-
426
-		// early return path if it is a deleted user
427
-		$user = $this->access->userManager->get($uid);
428
-		if($user instanceof OfflineUser) {
429
-			if($this->currentUserInDeletionProcess !== null
430
-				&& $this->currentUserInDeletionProcess === $user->getOCName()
431
-			) {
432
-				return $user->getHomePath();
433
-			} else {
434
-				throw new NoUserException($uid . ' is not a valid user anymore');
435
-			}
436
-		} else if ($user === null) {
437
-			throw new NoUserException($uid . ' is not a valid user anymore');
438
-		}
439
-
440
-		$path = $user->getHomePath();
441
-		$this->access->cacheUserHome($uid, $path);
442
-
443
-		return $path;
444
-	}
445
-
446
-	/**
447
-	 * get display name of the user
448
-	 * @param string $uid user ID of the user
449
-	 * @return string|false display name
450
-	 */
451
-	public function getDisplayName($uid) {
452
-		if ($this->userPluginManager->implementsActions(Backend::GET_DISPLAYNAME)) {
453
-			return $this->userPluginManager->getDisplayName($uid);
454
-		}
455
-
456
-		if(!$this->userExists($uid)) {
457
-			return false;
458
-		}
459
-
460
-		$cacheKey = 'getDisplayName'.$uid;
461
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
462
-			return $displayName;
463
-		}
464
-
465
-		//Check whether the display name is configured to have a 2nd feature
466
-		$additionalAttribute = $this->access->connection->ldapUserDisplayName2;
467
-		$displayName2 = '';
468
-		if ($additionalAttribute !== '') {
469
-			$displayName2 = $this->access->readAttribute(
470
-				$this->access->username2dn($uid),
471
-				$additionalAttribute);
472
-		}
473
-
474
-		$displayName = $this->access->readAttribute(
475
-			$this->access->username2dn($uid),
476
-			$this->access->connection->ldapUserDisplayName);
477
-
478
-		if($displayName && (count($displayName) > 0)) {
479
-			$displayName = $displayName[0];
480
-
481
-			if (is_array($displayName2)){
482
-				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
483
-			}
484
-
485
-			$user = $this->access->userManager->get($uid);
486
-			if ($user instanceof User) {
487
-				$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
488
-				$this->access->connection->writeToCache($cacheKey, $displayName);
489
-			}
490
-			if ($user instanceof OfflineUser) {
491
-				/** @var OfflineUser $user*/
492
-				$displayName = $user->getDisplayName();
493
-			}
494
-			return $displayName;
495
-		}
496
-
497
-		return null;
498
-	}
499
-
500
-	/**
501
-	 * set display name of the user
502
-	 * @param string $uid user ID of the user
503
-	 * @param string $displayName new display name of the user
504
-	 * @return string|false display name
505
-	 */
506
-	public function setDisplayName($uid, $displayName) {
507
-		if ($this->userPluginManager->implementsActions(Backend::SET_DISPLAYNAME)) {
508
-			return $this->userPluginManager->setDisplayName($uid, $displayName);
509
-		}
510
-		return false;
511
-	}
512
-
513
-	/**
514
-	 * Get a list of all display names
515
-	 *
516
-	 * @param string $search
517
-	 * @param string|null $limit
518
-	 * @param string|null $offset
519
-	 * @return array an array of all displayNames (value) and the corresponding uids (key)
520
-	 */
521
-	public function getDisplayNames($search = '', $limit = null, $offset = null) {
522
-		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
523
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
524
-			return $displayNames;
525
-		}
526
-
527
-		$displayNames = array();
528
-		$users = $this->getUsers($search, $limit, $offset);
529
-		foreach ($users as $user) {
530
-			$displayNames[$user] = $this->getDisplayName($user);
531
-		}
532
-		$this->access->connection->writeToCache($cacheKey, $displayNames);
533
-		return $displayNames;
534
-	}
535
-
536
-	/**
537
-	* Check if backend implements actions
538
-	* @param int $actions bitwise-or'ed actions
539
-	* @return boolean
540
-	*
541
-	* Returns the supported actions as int to be
542
-	* compared with \OC\User\Backend::CREATE_USER etc.
543
-	*/
544
-	public function implementsActions($actions) {
545
-		return (bool)((Backend::CHECK_PASSWORD
546
-			| Backend::GET_HOME
547
-			| Backend::GET_DISPLAYNAME
548
-			| (($this->access->connection->ldapUserAvatarRule !== 'none') ? Backend::PROVIDE_AVATAR : 0)
549
-			| Backend::COUNT_USERS
550
-			| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)
551
-			| $this->userPluginManager->getImplementedActions())
552
-			& $actions);
553
-	}
554
-
555
-	/**
556
-	 * @return bool
557
-	 */
558
-	public function hasUserListings() {
559
-		return true;
560
-	}
561
-
562
-	/**
563
-	 * counts the users in LDAP
564
-	 *
565
-	 * @return int|bool
566
-	 */
567
-	public function countUsers() {
568
-		if ($this->userPluginManager->implementsActions(Backend::COUNT_USERS)) {
569
-			return $this->userPluginManager->countUsers();
570
-		}
571
-
572
-		$filter = $this->access->getFilterForUserCount();
573
-		$cacheKey = 'countUsers-'.$filter;
574
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
575
-			return $entries;
576
-		}
577
-		$entries = $this->access->countUsers($filter);
578
-		$this->access->connection->writeToCache($cacheKey, $entries);
579
-		return $entries;
580
-	}
581
-
582
-	/**
583
-	 * Backend name to be shown in user management
584
-	 * @return string the name of the backend to be shown
585
-	 */
586
-	public function getBackendName(){
587
-		return 'LDAP';
588
-	}
151
+    /**
152
+     * returns the username for the given LDAP DN, if available
153
+     *
154
+     * @param string $dn
155
+     * @return string|false with the username
156
+     */
157
+    public function dn2UserName($dn) {
158
+        return $this->access->dn2username($dn);
159
+    }
160
+
161
+    /**
162
+     * returns an LDAP record based on a given login name
163
+     *
164
+     * @param string $loginName
165
+     * @return array
166
+     * @throws NotOnLDAP
167
+     */
168
+    public function getLDAPUserByLoginName($loginName) {
169
+        //find out dn of the user name
170
+        $attrs = $this->access->userManager->getAttributes();
171
+        $users = $this->access->fetchUsersByLoginName($loginName, $attrs);
172
+        if(count($users) < 1) {
173
+            throw new NotOnLDAP('No user available for the given login name on ' .
174
+                $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
175
+        }
176
+        return $users[0];
177
+    }
178
+
179
+    /**
180
+     * Check if the password is correct without logging in the user
181
+     *
182
+     * @param string $uid The username
183
+     * @param string $password The password
184
+     * @return false|string
185
+     */
186
+    public function checkPassword($uid, $password) {
187
+        try {
188
+            $ldapRecord = $this->getLDAPUserByLoginName($uid);
189
+        } catch(NotOnLDAP $e) {
190
+            if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
191
+                \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
192
+            }
193
+            return false;
194
+        }
195
+        $dn = $ldapRecord['dn'][0];
196
+        $user = $this->access->userManager->get($dn);
197
+
198
+        if(!$user instanceof User) {
199
+            Util::writeLog('user_ldap',
200
+                'LDAP Login: Could not get user object for DN ' . $dn .
201
+                '. Maybe the LDAP entry has no set display name attribute?',
202
+                Util::WARN);
203
+            return false;
204
+        }
205
+        if($user->getUsername() !== false) {
206
+            //are the credentials OK?
207
+            if(!$this->access->areCredentialsValid($dn, $password)) {
208
+                return false;
209
+            }
210
+
211
+            $this->access->cacheUserExists($user->getUsername());
212
+            $user->processAttributes($ldapRecord);
213
+            $user->markLogin();
214
+
215
+            return $user->getUsername();
216
+        }
217
+
218
+        return false;
219
+    }
220
+
221
+    /**
222
+     * Set password
223
+     * @param string $uid The username
224
+     * @param string $password The new password
225
+     * @return bool
226
+     */
227
+    public function setPassword($uid, $password) {
228
+        if ($this->userPluginManager->implementsActions(Backend::SET_PASSWORD)) {
229
+            return $this->userPluginManager->setPassword($uid, $password);
230
+        }
231
+
232
+        $user = $this->access->userManager->get($uid);
233
+
234
+        if(!$user instanceof User) {
235
+            throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
236
+                '. Maybe the LDAP entry has no set display name attribute?');
237
+        }
238
+        if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
239
+            $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
240
+            $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
241
+            if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
242
+                //remove last password expiry warning if any
243
+                $notification = $this->notificationManager->createNotification();
244
+                $notification->setApp('user_ldap')
245
+                    ->setUser($uid)
246
+                    ->setObject('pwd_exp_warn', $uid)
247
+                ;
248
+                $this->notificationManager->markProcessed($notification);
249
+            }
250
+            return true;
251
+        }
252
+
253
+        return false;
254
+    }
255
+
256
+    /**
257
+     * Get a list of all users
258
+     *
259
+     * @param string $search
260
+     * @param integer $limit
261
+     * @param integer $offset
262
+     * @return string[] an array of all uids
263
+     */
264
+    public function getUsers($search = '', $limit = 10, $offset = 0) {
265
+        $search = $this->access->escapeFilterPart($search, true);
266
+        $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
267
+
268
+        //check if users are cached, if so return
269
+        $ldap_users = $this->access->connection->getFromCache($cachekey);
270
+        if(!is_null($ldap_users)) {
271
+            return $ldap_users;
272
+        }
273
+
274
+        // if we'd pass -1 to LDAP search, we'd end up in a Protocol
275
+        // error. With a limit of 0, we get 0 results. So we pass null.
276
+        if($limit <= 0) {
277
+            $limit = null;
278
+        }
279
+        $filter = $this->access->combineFilterWithAnd(array(
280
+            $this->access->connection->ldapUserFilter,
281
+            $this->access->connection->ldapUserDisplayName . '=*',
282
+            $this->access->getFilterPartForUserSearch($search)
283
+        ));
284
+
285
+        Util::writeLog('user_ldap',
286
+            'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
287
+            Util::DEBUG);
288
+        //do the search and translate results to Nextcloud names
289
+        $ldap_users = $this->access->fetchListOfUsers(
290
+            $filter,
291
+            $this->access->userManager->getAttributes(true),
292
+            $limit, $offset);
293
+        $ldap_users = $this->access->nextcloudUserNames($ldap_users);
294
+        Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
295
+
296
+        $this->access->connection->writeToCache($cachekey, $ldap_users);
297
+        return $ldap_users;
298
+    }
299
+
300
+    /**
301
+     * checks whether a user is still available on LDAP
302
+     *
303
+     * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
304
+     * name or an instance of that user
305
+     * @return bool
306
+     * @throws \Exception
307
+     * @throws \OC\ServerNotAvailableException
308
+     */
309
+    public function userExistsOnLDAP($user) {
310
+        if(is_string($user)) {
311
+            $user = $this->access->userManager->get($user);
312
+        }
313
+        if(is_null($user)) {
314
+            return false;
315
+        }
316
+
317
+        $dn = $user->getDN();
318
+        //check if user really still exists by reading its entry
319
+        if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
320
+            try {
321
+                $uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
322
+                if (!$uuid) {
323
+                    return false;
324
+                }
325
+                $newDn = $this->access->getUserDnByUuid($uuid);
326
+                //check if renamed user is still valid by reapplying the ldap filter
327
+                if ($newDn === $dn || !is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
328
+                    return false;
329
+                }
330
+                $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
331
+                return true;
332
+            } catch (ServerNotAvailableException $e) {
333
+                throw $e;
334
+            } catch (\Exception $e) {
335
+                return false;
336
+            }
337
+        }
338
+
339
+        if($user instanceof OfflineUser) {
340
+            $user->unmark();
341
+        }
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * check if a user exists
348
+     * @param string $uid the username
349
+     * @return boolean
350
+     * @throws \Exception when connection could not be established
351
+     */
352
+    public function userExists($uid) {
353
+        $userExists = $this->access->connection->getFromCache('userExists'.$uid);
354
+        if(!is_null($userExists)) {
355
+            return (bool)$userExists;
356
+        }
357
+        //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
358
+        $user = $this->access->userManager->get($uid);
359
+
360
+        if(is_null($user)) {
361
+            Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
362
+                $this->access->connection->ldapHost, Util::DEBUG);
363
+            $this->access->connection->writeToCache('userExists'.$uid, false);
364
+            return false;
365
+        } else if($user instanceof OfflineUser) {
366
+            //express check for users marked as deleted. Returning true is
367
+            //necessary for cleanup
368
+            return true;
369
+        }
370
+
371
+        $result = $this->userExistsOnLDAP($user);
372
+        $this->access->connection->writeToCache('userExists'.$uid, $result);
373
+        return $result;
374
+    }
375
+
376
+    /**
377
+     * returns whether a user was deleted in LDAP
378
+     *
379
+     * @param string $uid The username of the user to delete
380
+     * @return bool
381
+     */
382
+    public function deleteUser($uid) {
383
+        if ($this->userPluginManager->canDeleteUser()) {
384
+            return $this->userPluginManager->deleteUser($uid);
385
+        }
386
+
387
+        $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
388
+        if(intval($marked) === 0) {
389
+            \OC::$server->getLogger()->notice(
390
+                'User '.$uid . ' is not marked as deleted, not cleaning up.',
391
+                array('app' => 'user_ldap'));
392
+            return false;
393
+        }
394
+        \OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
395
+            array('app' => 'user_ldap'));
396
+
397
+        $this->access->getUserMapper()->unmap($uid);
398
+        $this->access->userManager->invalidate($uid);
399
+        return true;
400
+    }
401
+
402
+    /**
403
+     * get the user's home directory
404
+     *
405
+     * @param string $uid the username
406
+     * @return bool|string
407
+     * @throws NoUserException
408
+     * @throws \Exception
409
+     */
410
+    public function getHome($uid) {
411
+        // user Exists check required as it is not done in user proxy!
412
+        if(!$this->userExists($uid)) {
413
+            return false;
414
+        }
415
+
416
+        if ($this->userPluginManager->implementsActions(Backend::GET_HOME)) {
417
+            return $this->userPluginManager->getHome($uid);
418
+        }
419
+
420
+        $cacheKey = 'getHome'.$uid;
421
+        $path = $this->access->connection->getFromCache($cacheKey);
422
+        if(!is_null($path)) {
423
+            return $path;
424
+        }
425
+
426
+        // early return path if it is a deleted user
427
+        $user = $this->access->userManager->get($uid);
428
+        if($user instanceof OfflineUser) {
429
+            if($this->currentUserInDeletionProcess !== null
430
+                && $this->currentUserInDeletionProcess === $user->getOCName()
431
+            ) {
432
+                return $user->getHomePath();
433
+            } else {
434
+                throw new NoUserException($uid . ' is not a valid user anymore');
435
+            }
436
+        } else if ($user === null) {
437
+            throw new NoUserException($uid . ' is not a valid user anymore');
438
+        }
439
+
440
+        $path = $user->getHomePath();
441
+        $this->access->cacheUserHome($uid, $path);
442
+
443
+        return $path;
444
+    }
445
+
446
+    /**
447
+     * get display name of the user
448
+     * @param string $uid user ID of the user
449
+     * @return string|false display name
450
+     */
451
+    public function getDisplayName($uid) {
452
+        if ($this->userPluginManager->implementsActions(Backend::GET_DISPLAYNAME)) {
453
+            return $this->userPluginManager->getDisplayName($uid);
454
+        }
455
+
456
+        if(!$this->userExists($uid)) {
457
+            return false;
458
+        }
459
+
460
+        $cacheKey = 'getDisplayName'.$uid;
461
+        if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
462
+            return $displayName;
463
+        }
464
+
465
+        //Check whether the display name is configured to have a 2nd feature
466
+        $additionalAttribute = $this->access->connection->ldapUserDisplayName2;
467
+        $displayName2 = '';
468
+        if ($additionalAttribute !== '') {
469
+            $displayName2 = $this->access->readAttribute(
470
+                $this->access->username2dn($uid),
471
+                $additionalAttribute);
472
+        }
473
+
474
+        $displayName = $this->access->readAttribute(
475
+            $this->access->username2dn($uid),
476
+            $this->access->connection->ldapUserDisplayName);
477
+
478
+        if($displayName && (count($displayName) > 0)) {
479
+            $displayName = $displayName[0];
480
+
481
+            if (is_array($displayName2)){
482
+                $displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
483
+            }
484
+
485
+            $user = $this->access->userManager->get($uid);
486
+            if ($user instanceof User) {
487
+                $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
488
+                $this->access->connection->writeToCache($cacheKey, $displayName);
489
+            }
490
+            if ($user instanceof OfflineUser) {
491
+                /** @var OfflineUser $user*/
492
+                $displayName = $user->getDisplayName();
493
+            }
494
+            return $displayName;
495
+        }
496
+
497
+        return null;
498
+    }
499
+
500
+    /**
501
+     * set display name of the user
502
+     * @param string $uid user ID of the user
503
+     * @param string $displayName new display name of the user
504
+     * @return string|false display name
505
+     */
506
+    public function setDisplayName($uid, $displayName) {
507
+        if ($this->userPluginManager->implementsActions(Backend::SET_DISPLAYNAME)) {
508
+            return $this->userPluginManager->setDisplayName($uid, $displayName);
509
+        }
510
+        return false;
511
+    }
512
+
513
+    /**
514
+     * Get a list of all display names
515
+     *
516
+     * @param string $search
517
+     * @param string|null $limit
518
+     * @param string|null $offset
519
+     * @return array an array of all displayNames (value) and the corresponding uids (key)
520
+     */
521
+    public function getDisplayNames($search = '', $limit = null, $offset = null) {
522
+        $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
523
+        if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
524
+            return $displayNames;
525
+        }
526
+
527
+        $displayNames = array();
528
+        $users = $this->getUsers($search, $limit, $offset);
529
+        foreach ($users as $user) {
530
+            $displayNames[$user] = $this->getDisplayName($user);
531
+        }
532
+        $this->access->connection->writeToCache($cacheKey, $displayNames);
533
+        return $displayNames;
534
+    }
535
+
536
+    /**
537
+     * Check if backend implements actions
538
+     * @param int $actions bitwise-or'ed actions
539
+     * @return boolean
540
+     *
541
+     * Returns the supported actions as int to be
542
+     * compared with \OC\User\Backend::CREATE_USER etc.
543
+     */
544
+    public function implementsActions($actions) {
545
+        return (bool)((Backend::CHECK_PASSWORD
546
+            | Backend::GET_HOME
547
+            | Backend::GET_DISPLAYNAME
548
+            | (($this->access->connection->ldapUserAvatarRule !== 'none') ? Backend::PROVIDE_AVATAR : 0)
549
+            | Backend::COUNT_USERS
550
+            | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)
551
+            | $this->userPluginManager->getImplementedActions())
552
+            & $actions);
553
+    }
554
+
555
+    /**
556
+     * @return bool
557
+     */
558
+    public function hasUserListings() {
559
+        return true;
560
+    }
561
+
562
+    /**
563
+     * counts the users in LDAP
564
+     *
565
+     * @return int|bool
566
+     */
567
+    public function countUsers() {
568
+        if ($this->userPluginManager->implementsActions(Backend::COUNT_USERS)) {
569
+            return $this->userPluginManager->countUsers();
570
+        }
571
+
572
+        $filter = $this->access->getFilterForUserCount();
573
+        $cacheKey = 'countUsers-'.$filter;
574
+        if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
575
+            return $entries;
576
+        }
577
+        $entries = $this->access->countUsers($filter);
578
+        $this->access->connection->writeToCache($cacheKey, $entries);
579
+        return $entries;
580
+    }
581
+
582
+    /**
583
+     * Backend name to be shown in user management
584
+     * @return string the name of the backend to be shown
585
+     */
586
+    public function getBackendName(){
587
+        return 'LDAP';
588
+    }
589 589
 	
590
-	/**
591
-	 * Return access for LDAP interaction.
592
-	 * @param string $uid
593
-	 * @return Access instance of Access for LDAP interaction
594
-	 */
595
-	public function getLDAPAccess($uid) {
596
-		return $this->access;
597
-	}
590
+    /**
591
+     * Return access for LDAP interaction.
592
+     * @param string $uid
593
+     * @return Access instance of Access for LDAP interaction
594
+     */
595
+    public function getLDAPAccess($uid) {
596
+        return $this->access;
597
+    }
598 598
 	
599
-	/**
600
-	 * Return LDAP connection resource from a cloned connection.
601
-	 * The cloned connection needs to be closed manually.
602
-	 * of the current access.
603
-	 * @param string $uid
604
-	 * @return resource of the LDAP connection
605
-	 */
606
-	public function getNewLDAPConnection($uid) {
607
-		$connection = clone $this->access->getConnection();
608
-		return $connection->getConnectionResource();
609
-	}
610
-
611
-	/**
612
-	 * create new user
613
-	 * @param string $username username of the new user
614
-	 * @param string $password password of the new user
615
-	 * @return bool was the user created?
616
-	 */
617
-	public function createUser($username, $password) {
618
-		if ($this->userPluginManager->implementsActions(Backend::CREATE_USER)) {
619
-			return $this->userPluginManager->createUser($username, $password);
620
-		}
621
-		return false;
622
-	}
599
+    /**
600
+     * Return LDAP connection resource from a cloned connection.
601
+     * The cloned connection needs to be closed manually.
602
+     * of the current access.
603
+     * @param string $uid
604
+     * @return resource of the LDAP connection
605
+     */
606
+    public function getNewLDAPConnection($uid) {
607
+        $connection = clone $this->access->getConnection();
608
+        return $connection->getConnectionResource();
609
+    }
610
+
611
+    /**
612
+     * create new user
613
+     * @param string $username username of the new user
614
+     * @param string $password password of the new user
615
+     * @return bool was the user created?
616
+     */
617
+    public function createUser($username, $password) {
618
+        if ($this->userPluginManager->implementsActions(Backend::CREATE_USER)) {
619
+            return $this->userPluginManager->createUser($username, $password);
620
+        }
621
+        return false;
622
+    }
623 623
 
624 624
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
 			return $this->userPluginManager->canChangeAvatar($uid);
103 103
 		}
104 104
 
105
-		if(!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
105
+		if (!$this->implementsActions(Backend::PROVIDE_AVATAR)) {
106 106
 			return true;
107 107
 		}
108 108
 
109 109
 		$user = $this->access->userManager->get($uid);
110
-		if(!$user instanceof User) {
110
+		if (!$user instanceof User) {
111 111
 			return false;
112 112
 		}
113 113
 		$imageData = $user->getAvatarImage();
114
-		if($imageData === false) {
114
+		if ($imageData === false) {
115 115
 			return true;
116 116
 		}
117 117
 		return !$user->updateAvatar(true);
@@ -126,14 +126,14 @@  discard block
 block discarded – undo
126 126
 	public function loginName2UserName($loginName) {
127 127
 		$cacheKey = 'loginName2UserName-'.$loginName;
128 128
 		$username = $this->access->connection->getFromCache($cacheKey);
129
-		if(!is_null($username)) {
129
+		if (!is_null($username)) {
130 130
 			return $username;
131 131
 		}
132 132
 
133 133
 		try {
134 134
 			$ldapRecord = $this->getLDAPUserByLoginName($loginName);
135 135
 			$user = $this->access->userManager->get($ldapRecord['dn'][0]);
136
-			if($user instanceof OfflineUser) {
136
+			if ($user instanceof OfflineUser) {
137 137
 				// this path is not really possible, however get() is documented
138 138
 				// to return User or OfflineUser so we are very defensive here.
139 139
 				$this->access->connection->writeToCache($cacheKey, false);
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 		//find out dn of the user name
170 170
 		$attrs = $this->access->userManager->getAttributes();
171 171
 		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
172
-		if(count($users) < 1) {
173
-			throw new NotOnLDAP('No user available for the given login name on ' .
174
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
172
+		if (count($users) < 1) {
173
+			throw new NotOnLDAP('No user available for the given login name on '.
174
+				$this->access->connection->ldapHost.':'.$this->access->connection->ldapPort);
175 175
 		}
176 176
 		return $users[0];
177 177
 	}
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	public function checkPassword($uid, $password) {
187 187
 		try {
188 188
 			$ldapRecord = $this->getLDAPUserByLoginName($uid);
189
-		} catch(NotOnLDAP $e) {
190
-			if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
189
+		} catch (NotOnLDAP $e) {
190
+			if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
191 191
 				\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
192 192
 			}
193 193
 			return false;
@@ -195,16 +195,16 @@  discard block
 block discarded – undo
195 195
 		$dn = $ldapRecord['dn'][0];
196 196
 		$user = $this->access->userManager->get($dn);
197 197
 
198
-		if(!$user instanceof User) {
198
+		if (!$user instanceof User) {
199 199
 			Util::writeLog('user_ldap',
200
-				'LDAP Login: Could not get user object for DN ' . $dn .
200
+				'LDAP Login: Could not get user object for DN '.$dn.
201 201
 				'. Maybe the LDAP entry has no set display name attribute?',
202 202
 				Util::WARN);
203 203
 			return false;
204 204
 		}
205
-		if($user->getUsername() !== false) {
205
+		if ($user->getUsername() !== false) {
206 206
 			//are the credentials OK?
207
-			if(!$this->access->areCredentialsValid($dn, $password)) {
207
+			if (!$this->access->areCredentialsValid($dn, $password)) {
208 208
 				return false;
209 209
 			}
210 210
 
@@ -231,11 +231,11 @@  discard block
 block discarded – undo
231 231
 
232 232
 		$user = $this->access->userManager->get($uid);
233 233
 
234
-		if(!$user instanceof User) {
235
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
234
+		if (!$user instanceof User) {
235
+			throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid.
236 236
 				'. Maybe the LDAP entry has no set display name attribute?');
237 237
 		}
238
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
238
+		if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
239 239
 			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
240 240
 			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
241 241
 			if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
@@ -267,18 +267,18 @@  discard block
 block discarded – undo
267 267
 
268 268
 		//check if users are cached, if so return
269 269
 		$ldap_users = $this->access->connection->getFromCache($cachekey);
270
-		if(!is_null($ldap_users)) {
270
+		if (!is_null($ldap_users)) {
271 271
 			return $ldap_users;
272 272
 		}
273 273
 
274 274
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
275 275
 		// error. With a limit of 0, we get 0 results. So we pass null.
276
-		if($limit <= 0) {
276
+		if ($limit <= 0) {
277 277
 			$limit = null;
278 278
 		}
279 279
 		$filter = $this->access->combineFilterWithAnd(array(
280 280
 			$this->access->connection->ldapUserFilter,
281
-			$this->access->connection->ldapUserDisplayName . '=*',
281
+			$this->access->connection->ldapUserDisplayName.'=*',
282 282
 			$this->access->getFilterPartForUserSearch($search)
283 283
 		));
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 			$this->access->userManager->getAttributes(true),
292 292
 			$limit, $offset);
293 293
 		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
294
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
294
+		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG);
295 295
 
296 296
 		$this->access->connection->writeToCache($cachekey, $ldap_users);
297 297
 		return $ldap_users;
@@ -307,16 +307,16 @@  discard block
 block discarded – undo
307 307
 	 * @throws \OC\ServerNotAvailableException
308 308
 	 */
309 309
 	public function userExistsOnLDAP($user) {
310
-		if(is_string($user)) {
310
+		if (is_string($user)) {
311 311
 			$user = $this->access->userManager->get($user);
312 312
 		}
313
-		if(is_null($user)) {
313
+		if (is_null($user)) {
314 314
 			return false;
315 315
 		}
316 316
 
317 317
 		$dn = $user->getDN();
318 318
 		//check if user really still exists by reading its entry
319
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
319
+		if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
320 320
 			try {
321 321
 				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
322 322
 				if (!$uuid) {
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 			}
337 337
 		}
338 338
 
339
-		if($user instanceof OfflineUser) {
339
+		if ($user instanceof OfflineUser) {
340 340
 			$user->unmark();
341 341
 		}
342 342
 
@@ -351,18 +351,18 @@  discard block
 block discarded – undo
351 351
 	 */
352 352
 	public function userExists($uid) {
353 353
 		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
354
-		if(!is_null($userExists)) {
355
-			return (bool)$userExists;
354
+		if (!is_null($userExists)) {
355
+			return (bool) $userExists;
356 356
 		}
357 357
 		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
358 358
 		$user = $this->access->userManager->get($uid);
359 359
 
360
-		if(is_null($user)) {
360
+		if (is_null($user)) {
361 361
 			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
362 362
 				$this->access->connection->ldapHost, Util::DEBUG);
363 363
 			$this->access->connection->writeToCache('userExists'.$uid, false);
364 364
 			return false;
365
-		} else if($user instanceof OfflineUser) {
365
+		} else if ($user instanceof OfflineUser) {
366 366
 			//express check for users marked as deleted. Returning true is
367 367
 			//necessary for cleanup
368 368
 			return true;
@@ -385,13 +385,13 @@  discard block
 block discarded – undo
385 385
 		}
386 386
 
387 387
 		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
388
-		if(intval($marked) === 0) {
388
+		if (intval($marked) === 0) {
389 389
 			\OC::$server->getLogger()->notice(
390
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
390
+				'User '.$uid.' is not marked as deleted, not cleaning up.',
391 391
 				array('app' => 'user_ldap'));
392 392
 			return false;
393 393
 		}
394
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
394
+		\OC::$server->getLogger()->info('Cleaning up after user '.$uid,
395 395
 			array('app' => 'user_ldap'));
396 396
 
397 397
 		$this->access->getUserMapper()->unmap($uid);
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 	 */
410 410
 	public function getHome($uid) {
411 411
 		// user Exists check required as it is not done in user proxy!
412
-		if(!$this->userExists($uid)) {
412
+		if (!$this->userExists($uid)) {
413 413
 			return false;
414 414
 		}
415 415
 
@@ -419,22 +419,22 @@  discard block
 block discarded – undo
419 419
 
420 420
 		$cacheKey = 'getHome'.$uid;
421 421
 		$path = $this->access->connection->getFromCache($cacheKey);
422
-		if(!is_null($path)) {
422
+		if (!is_null($path)) {
423 423
 			return $path;
424 424
 		}
425 425
 
426 426
 		// early return path if it is a deleted user
427 427
 		$user = $this->access->userManager->get($uid);
428
-		if($user instanceof OfflineUser) {
429
-			if($this->currentUserInDeletionProcess !== null
428
+		if ($user instanceof OfflineUser) {
429
+			if ($this->currentUserInDeletionProcess !== null
430 430
 				&& $this->currentUserInDeletionProcess === $user->getOCName()
431 431
 			) {
432 432
 				return $user->getHomePath();
433 433
 			} else {
434
-				throw new NoUserException($uid . ' is not a valid user anymore');
434
+				throw new NoUserException($uid.' is not a valid user anymore');
435 435
 			}
436 436
 		} else if ($user === null) {
437
-			throw new NoUserException($uid . ' is not a valid user anymore');
437
+			throw new NoUserException($uid.' is not a valid user anymore');
438 438
 		}
439 439
 
440 440
 		$path = $user->getHomePath();
@@ -453,12 +453,12 @@  discard block
 block discarded – undo
453 453
 			return $this->userPluginManager->getDisplayName($uid);
454 454
 		}
455 455
 
456
-		if(!$this->userExists($uid)) {
456
+		if (!$this->userExists($uid)) {
457 457
 			return false;
458 458
 		}
459 459
 
460 460
 		$cacheKey = 'getDisplayName'.$uid;
461
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
461
+		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
462 462
 			return $displayName;
463 463
 		}
464 464
 
@@ -475,10 +475,10 @@  discard block
 block discarded – undo
475 475
 			$this->access->username2dn($uid),
476 476
 			$this->access->connection->ldapUserDisplayName);
477 477
 
478
-		if($displayName && (count($displayName) > 0)) {
478
+		if ($displayName && (count($displayName) > 0)) {
479 479
 			$displayName = $displayName[0];
480 480
 
481
-			if (is_array($displayName2)){
481
+			if (is_array($displayName2)) {
482 482
 				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
483 483
 			}
484 484
 
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 	 */
521 521
 	public function getDisplayNames($search = '', $limit = null, $offset = null) {
522 522
 		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
523
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
523
+		if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
524 524
 			return $displayNames;
525 525
 		}
526 526
 
@@ -542,12 +542,12 @@  discard block
 block discarded – undo
542 542
 	* compared with \OC\User\Backend::CREATE_USER etc.
543 543
 	*/
544 544
 	public function implementsActions($actions) {
545
-		return (bool)((Backend::CHECK_PASSWORD
545
+		return (bool) ((Backend::CHECK_PASSWORD
546 546
 			| Backend::GET_HOME
547 547
 			| Backend::GET_DISPLAYNAME
548 548
 			| (($this->access->connection->ldapUserAvatarRule !== 'none') ? Backend::PROVIDE_AVATAR : 0)
549 549
 			| Backend::COUNT_USERS
550
-			| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)
550
+			| ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)
551 551
 			| $this->userPluginManager->getImplementedActions())
552 552
 			& $actions);
553 553
 	}
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 
572 572
 		$filter = $this->access->getFilterForUserCount();
573 573
 		$cacheKey = 'countUsers-'.$filter;
574
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
574
+		if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
575 575
 			return $entries;
576 576
 		}
577 577
 		$entries = $this->access->countUsers($filter);
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 	 * Backend name to be shown in user management
584 584
 	 * @return string the name of the backend to be shown
585 585
 	 */
586
-	public function getBackendName(){
586
+	public function getBackendName() {
587 587
 		return 'LDAP';
588 588
 	}
589 589
 	
Please login to merge, or discard this patch.
apps/admin_audit/lib/Actions/UserManagement.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -34,80 +34,80 @@
 block discarded – undo
34 34
  * @package OCA\AdminAudit\Actions
35 35
  */
36 36
 class UserManagement extends Action {
37
-	/**
38
-	 * Log creation of users
39
-	 *
40
-	 * @param array $params
41
-	 */
42
-	public function create(array $params) {
43
-		$this->log(
44
-			'User created: "%s"',
45
-			$params,
46
-			[
47
-				'uid',
48
-			]
49
-		);
50
-	}
37
+    /**
38
+     * Log creation of users
39
+     *
40
+     * @param array $params
41
+     */
42
+    public function create(array $params) {
43
+        $this->log(
44
+            'User created: "%s"',
45
+            $params,
46
+            [
47
+                'uid',
48
+            ]
49
+        );
50
+    }
51 51
 
52
-	/**
53
-	 * Log deletion of users
54
-	 *
55
-	 * @param array $params
56
-	 */
57
-	public function delete(array $params) {
58
-		$this->log(
59
-			'User deleted: "%s"',
60
-			$params,
61
-			[
62
-				'uid',
63
-			]
64
-		);
65
-	}
52
+    /**
53
+     * Log deletion of users
54
+     *
55
+     * @param array $params
56
+     */
57
+    public function delete(array $params) {
58
+        $this->log(
59
+            'User deleted: "%s"',
60
+            $params,
61
+            [
62
+                'uid',
63
+            ]
64
+        );
65
+    }
66 66
 
67
-	/**
68
-	 * Log enabling of users
69
-	 *
70
-	 * @param array $params
71
-	 */
72
-	public function change(array $params) {
73
-		switch($params['feature']) {
74
-			case 'enabled':
75
-				$this->log(
76
-					$params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
77
-					['user' => $params['user']->getUID()],
78
-					[
79
-						'user',
80
-					]
81
-				);
82
-				break;
83
-			case 'eMailAddress':
84
-				$this->log(
85
-					'Email address changed for user %s',
86
-					['user' => $params['user']->getUID()],
87
-					[
88
-						'user',
89
-					]
90
-				);
91
-				break;
92
-		}
93
-	}
67
+    /**
68
+     * Log enabling of users
69
+     *
70
+     * @param array $params
71
+     */
72
+    public function change(array $params) {
73
+        switch($params['feature']) {
74
+            case 'enabled':
75
+                $this->log(
76
+                    $params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
77
+                    ['user' => $params['user']->getUID()],
78
+                    [
79
+                        'user',
80
+                    ]
81
+                );
82
+                break;
83
+            case 'eMailAddress':
84
+                $this->log(
85
+                    'Email address changed for user %s',
86
+                    ['user' => $params['user']->getUID()],
87
+                    [
88
+                        'user',
89
+                    ]
90
+                );
91
+                break;
92
+        }
93
+    }
94 94
 
95
-	/**
96
-	 * Logs changing of the user scope
97
-	 *
98
-	 * @param IUser $user
99
-	 */
100
-	public function setPassword(IUser $user) {
101
-		if($user->getBackendClassName() === 'Database') {
102
-			$this->log(
103
-				'Password of user "%s" has been changed',
104
-				[
105
-					'user' => $user->getUID(),
106
-				],
107
-				[
108
-					'user',
109
-				]
110
-			);
111
-		}
112
-	}
95
+    /**
96
+     * Logs changing of the user scope
97
+     *
98
+     * @param IUser $user
99
+     */
100
+    public function setPassword(IUser $user) {
101
+        if($user->getBackendClassName() === 'Database') {
102
+            $this->log(
103
+                'Password of user "%s" has been changed',
104
+                [
105
+                    'user' => $user->getUID(),
106
+                ],
107
+                [
108
+                    'user',
109
+                ]
110
+            );
111
+        }
112
+    }
113 113
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 * @param array $params
71 71
 	 */
72 72
 	public function change(array $params) {
73
-		switch($params['feature']) {
73
+		switch ($params['feature']) {
74 74
 			case 'enabled':
75 75
 				$this->log(
76 76
 					$params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 * @param IUser $user
99 99
 	 */
100 100
 	public function setPassword(IUser $user) {
101
-		if($user->getBackendClassName() === 'Database') {
101
+		if ($user->getBackendClassName() === 'Database') {
102 102
 			$this->log(
103 103
 				'Password of user "%s" has been changed',
104 104
 				[
Please login to merge, or discard this patch.