@@ -43,416 +43,416 @@ |
||
43 | 43 | use \OCP\IUserBackend; |
44 | 44 | |
45 | 45 | class User implements IUser { |
46 | - /** @var string $uid */ |
|
47 | - private $uid; |
|
48 | - |
|
49 | - /** @var string $displayName */ |
|
50 | - private $displayName; |
|
51 | - |
|
52 | - /** @var UserInterface $backend */ |
|
53 | - private $backend; |
|
54 | - |
|
55 | - /** @var bool $enabled */ |
|
56 | - private $enabled; |
|
57 | - |
|
58 | - /** @var Emitter|Manager $emitter */ |
|
59 | - private $emitter; |
|
60 | - |
|
61 | - /** @var string $home */ |
|
62 | - private $home; |
|
63 | - |
|
64 | - /** @var int $lastLogin */ |
|
65 | - private $lastLogin; |
|
66 | - |
|
67 | - /** @var \OCP\IConfig $config */ |
|
68 | - private $config; |
|
69 | - |
|
70 | - /** @var IAvatarManager */ |
|
71 | - private $avatarManager; |
|
72 | - |
|
73 | - /** @var IURLGenerator */ |
|
74 | - private $urlGenerator; |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $uid |
|
78 | - * @param UserInterface $backend |
|
79 | - * @param \OC\Hooks\Emitter $emitter |
|
80 | - * @param IConfig|null $config |
|
81 | - * @param IURLGenerator $urlGenerator |
|
82 | - */ |
|
83 | - public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
84 | - $this->uid = $uid; |
|
85 | - $this->backend = $backend; |
|
86 | - $this->emitter = $emitter; |
|
87 | - if(is_null($config)) { |
|
88 | - $config = \OC::$server->getConfig(); |
|
89 | - } |
|
90 | - $this->config = $config; |
|
91 | - $this->urlGenerator = $urlGenerator; |
|
92 | - $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
93 | - $this->enabled = ($enabled === 'true'); |
|
94 | - $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
95 | - if (is_null($this->urlGenerator)) { |
|
96 | - $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * get the user id |
|
102 | - * |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function getUID() { |
|
106 | - return $this->uid; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function getDisplayName() { |
|
115 | - if (!isset($this->displayName)) { |
|
116 | - $displayName = ''; |
|
117 | - if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
118 | - // get display name and strip whitespace from the beginning and end of it |
|
119 | - $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
120 | - if (is_string($backendDisplayName)) { |
|
121 | - $displayName = trim($backendDisplayName); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - if (!empty($displayName)) { |
|
126 | - $this->displayName = $displayName; |
|
127 | - } else { |
|
128 | - $this->displayName = $this->uid; |
|
129 | - } |
|
130 | - } |
|
131 | - return $this->displayName; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * set the displayname for the user |
|
136 | - * |
|
137 | - * @param string $displayName |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function setDisplayName($displayName) { |
|
141 | - $displayName = trim($displayName); |
|
142 | - if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
143 | - $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
144 | - if ($result) { |
|
145 | - $this->displayName = $displayName; |
|
146 | - $this->triggerChange('displayName', $displayName); |
|
147 | - } |
|
148 | - return $result !== false; |
|
149 | - } else { |
|
150 | - return false; |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * set the email address of the user |
|
156 | - * |
|
157 | - * @param string|null $mailAddress |
|
158 | - * @return void |
|
159 | - * @since 9.0.0 |
|
160 | - */ |
|
161 | - public function setEMailAddress($mailAddress) { |
|
162 | - $oldMailAddress = $this->getEMailAddress(); |
|
163 | - if($mailAddress === '') { |
|
164 | - $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
165 | - } else { |
|
166 | - $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
167 | - } |
|
168 | - if($oldMailAddress !== $mailAddress) { |
|
169 | - $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
175 | - * login |
|
176 | - * |
|
177 | - * @return int |
|
178 | - */ |
|
179 | - public function getLastLogin() { |
|
180 | - return $this->lastLogin; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * updates the timestamp of the most recent login of this user |
|
185 | - */ |
|
186 | - public function updateLastLoginTimestamp() { |
|
187 | - $firstTimeLogin = ($this->lastLogin === 0); |
|
188 | - $this->lastLogin = time(); |
|
189 | - $this->config->setUserValue( |
|
190 | - $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
191 | - |
|
192 | - return $firstTimeLogin; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Delete the user |
|
197 | - * |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function delete() { |
|
201 | - if ($this->emitter) { |
|
202 | - $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
203 | - } |
|
204 | - // get the home now because it won't return it after user deletion |
|
205 | - $homePath = $this->getHome(); |
|
206 | - $result = $this->backend->deleteUser($this->uid); |
|
207 | - if ($result) { |
|
208 | - |
|
209 | - // FIXME: Feels like an hack - suggestions? |
|
210 | - |
|
211 | - $groupManager = \OC::$server->getGroupManager(); |
|
212 | - // We have to delete the user from all groups |
|
213 | - foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
214 | - $group = $groupManager->get($groupId); |
|
215 | - if ($group) { |
|
216 | - \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
217 | - $group->removeUser($this); |
|
218 | - \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
219 | - } |
|
220 | - } |
|
221 | - // Delete the user's keys in preferences |
|
222 | - \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
223 | - |
|
224 | - // Delete user files in /data/ |
|
225 | - if ($homePath !== false) { |
|
226 | - // FIXME: this operates directly on FS, should use View instead... |
|
227 | - // also this is not testable/mockable... |
|
228 | - \OC_Helper::rmdirr($homePath); |
|
229 | - } |
|
230 | - |
|
231 | - // Delete the users entry in the storage table |
|
232 | - Storage::remove('home::' . $this->uid); |
|
233 | - |
|
234 | - \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
235 | - \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
236 | - |
|
237 | - $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
238 | - $notification->setUser($this->uid); |
|
239 | - \OC::$server->getNotificationManager()->markProcessed($notification); |
|
240 | - |
|
241 | - /** @var AccountManager $accountManager */ |
|
242 | - $accountManager = \OC::$server->query(AccountManager::class); |
|
243 | - $accountManager->deleteUser($this); |
|
244 | - |
|
245 | - if ($this->emitter) { |
|
246 | - $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
247 | - } |
|
248 | - } |
|
249 | - return !($result === false); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Set the password of the user |
|
254 | - * |
|
255 | - * @param string $password |
|
256 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
257 | - * @return bool |
|
258 | - */ |
|
259 | - public function setPassword($password, $recoveryPassword = null) { |
|
260 | - if ($this->emitter) { |
|
261 | - $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
262 | - } |
|
263 | - if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
264 | - $result = $this->backend->setPassword($this->uid, $password); |
|
265 | - if ($this->emitter) { |
|
266 | - $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
267 | - } |
|
268 | - return !($result === false); |
|
269 | - } else { |
|
270 | - return false; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * get the users home folder to mount |
|
276 | - * |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function getHome() { |
|
280 | - if (!$this->home) { |
|
281 | - if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
282 | - $this->home = $home; |
|
283 | - } elseif ($this->config) { |
|
284 | - $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
285 | - } else { |
|
286 | - $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
287 | - } |
|
288 | - } |
|
289 | - return $this->home; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Get the name of the backend class the user is connected with |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function getBackendClassName() { |
|
298 | - if($this->backend instanceof IUserBackend) { |
|
299 | - return $this->backend->getBackendName(); |
|
300 | - } |
|
301 | - return get_class($this->backend); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * check if the backend allows the user to change his avatar on Personal page |
|
306 | - * |
|
307 | - * @return bool |
|
308 | - */ |
|
309 | - public function canChangeAvatar() { |
|
310 | - if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
311 | - return $this->backend->canChangeAvatar($this->uid); |
|
312 | - } |
|
313 | - return true; |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * check if the backend supports changing passwords |
|
318 | - * |
|
319 | - * @return bool |
|
320 | - */ |
|
321 | - public function canChangePassword() { |
|
322 | - return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * check if the backend supports changing display names |
|
327 | - * |
|
328 | - * @return bool |
|
329 | - */ |
|
330 | - public function canChangeDisplayName() { |
|
331 | - if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
332 | - return false; |
|
333 | - } |
|
334 | - return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * check if the user is enabled |
|
339 | - * |
|
340 | - * @return bool |
|
341 | - */ |
|
342 | - public function isEnabled() { |
|
343 | - return $this->enabled; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * set the enabled status for the user |
|
348 | - * |
|
349 | - * @param bool $enabled |
|
350 | - */ |
|
351 | - public function setEnabled($enabled) { |
|
352 | - $oldStatus = $this->isEnabled(); |
|
353 | - $this->enabled = $enabled; |
|
354 | - $enabled = ($enabled) ? 'true' : 'false'; |
|
355 | - if ($oldStatus !== $this->enabled) { |
|
356 | - $this->triggerChange('enabled', $enabled); |
|
357 | - $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled); |
|
358 | - } |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * get the users email address |
|
363 | - * |
|
364 | - * @return string|null |
|
365 | - * @since 9.0.0 |
|
366 | - */ |
|
367 | - public function getEMailAddress() { |
|
368 | - return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * get the users' quota |
|
373 | - * |
|
374 | - * @return string |
|
375 | - * @since 9.0.0 |
|
376 | - */ |
|
377 | - public function getQuota() { |
|
378 | - $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
379 | - if($quota === 'default') { |
|
380 | - $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
381 | - } |
|
382 | - return $quota; |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * set the users' quota |
|
387 | - * |
|
388 | - * @param string $quota |
|
389 | - * @return void |
|
390 | - * @since 9.0.0 |
|
391 | - */ |
|
392 | - public function setQuota($quota) { |
|
393 | - $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
|
394 | - if($quota !== 'none' and $quota !== 'default') { |
|
395 | - $quota = OC_Helper::computerFileSize($quota); |
|
396 | - $quota = OC_Helper::humanFileSize($quota); |
|
397 | - } |
|
398 | - $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
399 | - if($quota !== $oldQuota) { |
|
400 | - $this->triggerChange('quota', $quota); |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * get the avatar image if it exists |
|
406 | - * |
|
407 | - * @param int $size |
|
408 | - * @return IImage|null |
|
409 | - * @since 9.0.0 |
|
410 | - */ |
|
411 | - public function getAvatarImage($size) { |
|
412 | - // delay the initialization |
|
413 | - if (is_null($this->avatarManager)) { |
|
414 | - $this->avatarManager = \OC::$server->getAvatarManager(); |
|
415 | - } |
|
416 | - |
|
417 | - $avatar = $this->avatarManager->getAvatar($this->uid); |
|
418 | - $image = $avatar->get(-1); |
|
419 | - if ($image) { |
|
420 | - return $image; |
|
421 | - } |
|
422 | - |
|
423 | - return null; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * get the federation cloud id |
|
428 | - * |
|
429 | - * @return string |
|
430 | - * @since 9.0.0 |
|
431 | - */ |
|
432 | - public function getCloudId() { |
|
433 | - $uid = $this->getUID(); |
|
434 | - $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
435 | - $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
436 | - return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @param string $url |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - private function removeProtocolFromUrl($url) { |
|
444 | - if (strpos($url, 'https://') === 0) { |
|
445 | - return substr($url, strlen('https://')); |
|
446 | - } else if (strpos($url, 'http://') === 0) { |
|
447 | - return substr($url, strlen('http://')); |
|
448 | - } |
|
449 | - |
|
450 | - return $url; |
|
451 | - } |
|
452 | - |
|
453 | - public function triggerChange($feature, $value = null, $oldValue = null) { |
|
454 | - if ($this->emitter) { |
|
455 | - $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
456 | - } |
|
457 | - } |
|
46 | + /** @var string $uid */ |
|
47 | + private $uid; |
|
48 | + |
|
49 | + /** @var string $displayName */ |
|
50 | + private $displayName; |
|
51 | + |
|
52 | + /** @var UserInterface $backend */ |
|
53 | + private $backend; |
|
54 | + |
|
55 | + /** @var bool $enabled */ |
|
56 | + private $enabled; |
|
57 | + |
|
58 | + /** @var Emitter|Manager $emitter */ |
|
59 | + private $emitter; |
|
60 | + |
|
61 | + /** @var string $home */ |
|
62 | + private $home; |
|
63 | + |
|
64 | + /** @var int $lastLogin */ |
|
65 | + private $lastLogin; |
|
66 | + |
|
67 | + /** @var \OCP\IConfig $config */ |
|
68 | + private $config; |
|
69 | + |
|
70 | + /** @var IAvatarManager */ |
|
71 | + private $avatarManager; |
|
72 | + |
|
73 | + /** @var IURLGenerator */ |
|
74 | + private $urlGenerator; |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $uid |
|
78 | + * @param UserInterface $backend |
|
79 | + * @param \OC\Hooks\Emitter $emitter |
|
80 | + * @param IConfig|null $config |
|
81 | + * @param IURLGenerator $urlGenerator |
|
82 | + */ |
|
83 | + public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
84 | + $this->uid = $uid; |
|
85 | + $this->backend = $backend; |
|
86 | + $this->emitter = $emitter; |
|
87 | + if(is_null($config)) { |
|
88 | + $config = \OC::$server->getConfig(); |
|
89 | + } |
|
90 | + $this->config = $config; |
|
91 | + $this->urlGenerator = $urlGenerator; |
|
92 | + $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
93 | + $this->enabled = ($enabled === 'true'); |
|
94 | + $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
95 | + if (is_null($this->urlGenerator)) { |
|
96 | + $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * get the user id |
|
102 | + * |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function getUID() { |
|
106 | + return $this->uid; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function getDisplayName() { |
|
115 | + if (!isset($this->displayName)) { |
|
116 | + $displayName = ''; |
|
117 | + if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
118 | + // get display name and strip whitespace from the beginning and end of it |
|
119 | + $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
120 | + if (is_string($backendDisplayName)) { |
|
121 | + $displayName = trim($backendDisplayName); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + if (!empty($displayName)) { |
|
126 | + $this->displayName = $displayName; |
|
127 | + } else { |
|
128 | + $this->displayName = $this->uid; |
|
129 | + } |
|
130 | + } |
|
131 | + return $this->displayName; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * set the displayname for the user |
|
136 | + * |
|
137 | + * @param string $displayName |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function setDisplayName($displayName) { |
|
141 | + $displayName = trim($displayName); |
|
142 | + if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
143 | + $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
144 | + if ($result) { |
|
145 | + $this->displayName = $displayName; |
|
146 | + $this->triggerChange('displayName', $displayName); |
|
147 | + } |
|
148 | + return $result !== false; |
|
149 | + } else { |
|
150 | + return false; |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * set the email address of the user |
|
156 | + * |
|
157 | + * @param string|null $mailAddress |
|
158 | + * @return void |
|
159 | + * @since 9.0.0 |
|
160 | + */ |
|
161 | + public function setEMailAddress($mailAddress) { |
|
162 | + $oldMailAddress = $this->getEMailAddress(); |
|
163 | + if($mailAddress === '') { |
|
164 | + $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
165 | + } else { |
|
166 | + $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
167 | + } |
|
168 | + if($oldMailAddress !== $mailAddress) { |
|
169 | + $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
175 | + * login |
|
176 | + * |
|
177 | + * @return int |
|
178 | + */ |
|
179 | + public function getLastLogin() { |
|
180 | + return $this->lastLogin; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * updates the timestamp of the most recent login of this user |
|
185 | + */ |
|
186 | + public function updateLastLoginTimestamp() { |
|
187 | + $firstTimeLogin = ($this->lastLogin === 0); |
|
188 | + $this->lastLogin = time(); |
|
189 | + $this->config->setUserValue( |
|
190 | + $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
191 | + |
|
192 | + return $firstTimeLogin; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Delete the user |
|
197 | + * |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function delete() { |
|
201 | + if ($this->emitter) { |
|
202 | + $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
203 | + } |
|
204 | + // get the home now because it won't return it after user deletion |
|
205 | + $homePath = $this->getHome(); |
|
206 | + $result = $this->backend->deleteUser($this->uid); |
|
207 | + if ($result) { |
|
208 | + |
|
209 | + // FIXME: Feels like an hack - suggestions? |
|
210 | + |
|
211 | + $groupManager = \OC::$server->getGroupManager(); |
|
212 | + // We have to delete the user from all groups |
|
213 | + foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
214 | + $group = $groupManager->get($groupId); |
|
215 | + if ($group) { |
|
216 | + \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
217 | + $group->removeUser($this); |
|
218 | + \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
219 | + } |
|
220 | + } |
|
221 | + // Delete the user's keys in preferences |
|
222 | + \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
223 | + |
|
224 | + // Delete user files in /data/ |
|
225 | + if ($homePath !== false) { |
|
226 | + // FIXME: this operates directly on FS, should use View instead... |
|
227 | + // also this is not testable/mockable... |
|
228 | + \OC_Helper::rmdirr($homePath); |
|
229 | + } |
|
230 | + |
|
231 | + // Delete the users entry in the storage table |
|
232 | + Storage::remove('home::' . $this->uid); |
|
233 | + |
|
234 | + \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
235 | + \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
236 | + |
|
237 | + $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
238 | + $notification->setUser($this->uid); |
|
239 | + \OC::$server->getNotificationManager()->markProcessed($notification); |
|
240 | + |
|
241 | + /** @var AccountManager $accountManager */ |
|
242 | + $accountManager = \OC::$server->query(AccountManager::class); |
|
243 | + $accountManager->deleteUser($this); |
|
244 | + |
|
245 | + if ($this->emitter) { |
|
246 | + $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
247 | + } |
|
248 | + } |
|
249 | + return !($result === false); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Set the password of the user |
|
254 | + * |
|
255 | + * @param string $password |
|
256 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
257 | + * @return bool |
|
258 | + */ |
|
259 | + public function setPassword($password, $recoveryPassword = null) { |
|
260 | + if ($this->emitter) { |
|
261 | + $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
262 | + } |
|
263 | + if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
264 | + $result = $this->backend->setPassword($this->uid, $password); |
|
265 | + if ($this->emitter) { |
|
266 | + $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
267 | + } |
|
268 | + return !($result === false); |
|
269 | + } else { |
|
270 | + return false; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * get the users home folder to mount |
|
276 | + * |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function getHome() { |
|
280 | + if (!$this->home) { |
|
281 | + if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
282 | + $this->home = $home; |
|
283 | + } elseif ($this->config) { |
|
284 | + $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
285 | + } else { |
|
286 | + $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
287 | + } |
|
288 | + } |
|
289 | + return $this->home; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Get the name of the backend class the user is connected with |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function getBackendClassName() { |
|
298 | + if($this->backend instanceof IUserBackend) { |
|
299 | + return $this->backend->getBackendName(); |
|
300 | + } |
|
301 | + return get_class($this->backend); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * check if the backend allows the user to change his avatar on Personal page |
|
306 | + * |
|
307 | + * @return bool |
|
308 | + */ |
|
309 | + public function canChangeAvatar() { |
|
310 | + if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
311 | + return $this->backend->canChangeAvatar($this->uid); |
|
312 | + } |
|
313 | + return true; |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * check if the backend supports changing passwords |
|
318 | + * |
|
319 | + * @return bool |
|
320 | + */ |
|
321 | + public function canChangePassword() { |
|
322 | + return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * check if the backend supports changing display names |
|
327 | + * |
|
328 | + * @return bool |
|
329 | + */ |
|
330 | + public function canChangeDisplayName() { |
|
331 | + if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
332 | + return false; |
|
333 | + } |
|
334 | + return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * check if the user is enabled |
|
339 | + * |
|
340 | + * @return bool |
|
341 | + */ |
|
342 | + public function isEnabled() { |
|
343 | + return $this->enabled; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * set the enabled status for the user |
|
348 | + * |
|
349 | + * @param bool $enabled |
|
350 | + */ |
|
351 | + public function setEnabled($enabled) { |
|
352 | + $oldStatus = $this->isEnabled(); |
|
353 | + $this->enabled = $enabled; |
|
354 | + $enabled = ($enabled) ? 'true' : 'false'; |
|
355 | + if ($oldStatus !== $this->enabled) { |
|
356 | + $this->triggerChange('enabled', $enabled); |
|
357 | + $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled); |
|
358 | + } |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * get the users email address |
|
363 | + * |
|
364 | + * @return string|null |
|
365 | + * @since 9.0.0 |
|
366 | + */ |
|
367 | + public function getEMailAddress() { |
|
368 | + return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * get the users' quota |
|
373 | + * |
|
374 | + * @return string |
|
375 | + * @since 9.0.0 |
|
376 | + */ |
|
377 | + public function getQuota() { |
|
378 | + $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
379 | + if($quota === 'default') { |
|
380 | + $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
381 | + } |
|
382 | + return $quota; |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * set the users' quota |
|
387 | + * |
|
388 | + * @param string $quota |
|
389 | + * @return void |
|
390 | + * @since 9.0.0 |
|
391 | + */ |
|
392 | + public function setQuota($quota) { |
|
393 | + $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
|
394 | + if($quota !== 'none' and $quota !== 'default') { |
|
395 | + $quota = OC_Helper::computerFileSize($quota); |
|
396 | + $quota = OC_Helper::humanFileSize($quota); |
|
397 | + } |
|
398 | + $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
399 | + if($quota !== $oldQuota) { |
|
400 | + $this->triggerChange('quota', $quota); |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * get the avatar image if it exists |
|
406 | + * |
|
407 | + * @param int $size |
|
408 | + * @return IImage|null |
|
409 | + * @since 9.0.0 |
|
410 | + */ |
|
411 | + public function getAvatarImage($size) { |
|
412 | + // delay the initialization |
|
413 | + if (is_null($this->avatarManager)) { |
|
414 | + $this->avatarManager = \OC::$server->getAvatarManager(); |
|
415 | + } |
|
416 | + |
|
417 | + $avatar = $this->avatarManager->getAvatar($this->uid); |
|
418 | + $image = $avatar->get(-1); |
|
419 | + if ($image) { |
|
420 | + return $image; |
|
421 | + } |
|
422 | + |
|
423 | + return null; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * get the federation cloud id |
|
428 | + * |
|
429 | + * @return string |
|
430 | + * @since 9.0.0 |
|
431 | + */ |
|
432 | + public function getCloudId() { |
|
433 | + $uid = $this->getUID(); |
|
434 | + $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
435 | + $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
436 | + return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @param string $url |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + private function removeProtocolFromUrl($url) { |
|
444 | + if (strpos($url, 'https://') === 0) { |
|
445 | + return substr($url, strlen('https://')); |
|
446 | + } else if (strpos($url, 'http://') === 0) { |
|
447 | + return substr($url, strlen('http://')); |
|
448 | + } |
|
449 | + |
|
450 | + return $url; |
|
451 | + } |
|
452 | + |
|
453 | + public function triggerChange($feature, $value = null, $oldValue = null) { |
|
454 | + if ($this->emitter) { |
|
455 | + $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
456 | + } |
|
457 | + } |
|
458 | 458 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $this->uid = $uid; |
85 | 85 | $this->backend = $backend; |
86 | 86 | $this->emitter = $emitter; |
87 | - if(is_null($config)) { |
|
87 | + if (is_null($config)) { |
|
88 | 88 | $config = \OC::$server->getConfig(); |
89 | 89 | } |
90 | 90 | $this->config = $config; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function setEMailAddress($mailAddress) { |
162 | 162 | $oldMailAddress = $this->getEMailAddress(); |
163 | - if($mailAddress === '') { |
|
163 | + if ($mailAddress === '') { |
|
164 | 164 | $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
165 | 165 | } else { |
166 | 166 | $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
167 | 167 | } |
168 | - if($oldMailAddress !== $mailAddress) { |
|
168 | + if ($oldMailAddress !== $mailAddress) { |
|
169 | 169 | $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
170 | 170 | } |
171 | 171 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | } |
230 | 230 | |
231 | 231 | // Delete the users entry in the storage table |
232 | - Storage::remove('home::' . $this->uid); |
|
232 | + Storage::remove('home::'.$this->uid); |
|
233 | 233 | |
234 | 234 | \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
235 | 235 | \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
282 | 282 | $this->home = $home; |
283 | 283 | } elseif ($this->config) { |
284 | - $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
284 | + $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/'.$this->uid; |
|
285 | 285 | } else { |
286 | - $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
286 | + $this->home = \OC::$SERVERROOT.'/data/'.$this->uid; |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | return $this->home; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @return string |
296 | 296 | */ |
297 | 297 | public function getBackendClassName() { |
298 | - if($this->backend instanceof IUserBackend) { |
|
298 | + if ($this->backend instanceof IUserBackend) { |
|
299 | 299 | return $this->backend->getBackendName(); |
300 | 300 | } |
301 | 301 | return get_class($this->backend); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public function getQuota() { |
378 | 378 | $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
379 | - if($quota === 'default') { |
|
379 | + if ($quota === 'default') { |
|
380 | 380 | $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
381 | 381 | } |
382 | 382 | return $quota; |
@@ -391,12 +391,12 @@ discard block |
||
391 | 391 | */ |
392 | 392 | public function setQuota($quota) { |
393 | 393 | $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
394 | - if($quota !== 'none' and $quota !== 'default') { |
|
394 | + if ($quota !== 'none' and $quota !== 'default') { |
|
395 | 395 | $quota = OC_Helper::computerFileSize($quota); |
396 | 396 | $quota = OC_Helper::humanFileSize($quota); |
397 | 397 | } |
398 | 398 | $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
399 | - if($quota !== $oldQuota) { |
|
399 | + if ($quota !== $oldQuota) { |
|
400 | 400 | $this->triggerChange('quota', $quota); |
401 | 401 | } |
402 | 402 | } |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | public function getCloudId() { |
433 | 433 | $uid = $this->getUID(); |
434 | 434 | $server = $this->urlGenerator->getAbsoluteURL('/'); |
435 | - $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
435 | + $server = rtrim($this->removeProtocolFromUrl($server), '/'); |
|
436 | 436 | return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
437 | 437 | } |
438 | 438 |