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