@@ -44,419 +44,419 @@ |
||
| 44 | 44 | use \OCP\IUserBackend; |
| 45 | 45 | |
| 46 | 46 | class User implements IUser { |
| 47 | - /** @var string $uid */ |
|
| 48 | - private $uid; |
|
| 49 | - |
|
| 50 | - /** @var string $displayName */ |
|
| 51 | - private $displayName; |
|
| 52 | - |
|
| 53 | - /** @var UserInterface $backend */ |
|
| 54 | - private $backend; |
|
| 55 | - |
|
| 56 | - /** @var bool $enabled */ |
|
| 57 | - private $enabled; |
|
| 58 | - |
|
| 59 | - /** @var Emitter|Manager $emitter */ |
|
| 60 | - private $emitter; |
|
| 61 | - |
|
| 62 | - /** @var string $home */ |
|
| 63 | - private $home; |
|
| 64 | - |
|
| 65 | - /** @var int $lastLogin */ |
|
| 66 | - private $lastLogin; |
|
| 67 | - |
|
| 68 | - /** @var \OCP\IConfig $config */ |
|
| 69 | - private $config; |
|
| 70 | - |
|
| 71 | - /** @var IAvatarManager */ |
|
| 72 | - private $avatarManager; |
|
| 73 | - |
|
| 74 | - /** @var IURLGenerator */ |
|
| 75 | - private $urlGenerator; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $uid |
|
| 79 | - * @param UserInterface $backend |
|
| 80 | - * @param \OC\Hooks\Emitter $emitter |
|
| 81 | - * @param IConfig|null $config |
|
| 82 | - * @param IURLGenerator $urlGenerator |
|
| 83 | - */ |
|
| 84 | - public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
| 85 | - $this->uid = $uid; |
|
| 86 | - $this->backend = $backend; |
|
| 87 | - $this->emitter = $emitter; |
|
| 88 | - if(is_null($config)) { |
|
| 89 | - $config = \OC::$server->getConfig(); |
|
| 90 | - } |
|
| 91 | - $this->config = $config; |
|
| 92 | - $this->urlGenerator = $urlGenerator; |
|
| 93 | - $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
| 94 | - $this->enabled = ($enabled === 'true'); |
|
| 95 | - $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
| 96 | - if (is_null($this->urlGenerator)) { |
|
| 97 | - $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * get the user id |
|
| 103 | - * |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - public function getUID() { |
|
| 107 | - return $this->uid; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function getDisplayName() { |
|
| 116 | - if (!isset($this->displayName)) { |
|
| 117 | - $displayName = ''; |
|
| 118 | - if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
| 119 | - // get display name and strip whitespace from the beginning and end of it |
|
| 120 | - $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
| 121 | - if (is_string($backendDisplayName)) { |
|
| 122 | - $displayName = trim($backendDisplayName); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!empty($displayName)) { |
|
| 127 | - $this->displayName = $displayName; |
|
| 128 | - } else { |
|
| 129 | - $this->displayName = $this->uid; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $this->displayName; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * set the displayname for the user |
|
| 137 | - * |
|
| 138 | - * @param string $displayName |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - public function setDisplayName($displayName) { |
|
| 142 | - $displayName = trim($displayName); |
|
| 143 | - if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
| 144 | - $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
| 145 | - if ($result) { |
|
| 146 | - $this->displayName = $displayName; |
|
| 147 | - $this->triggerChange('displayName', $displayName); |
|
| 148 | - } |
|
| 149 | - return $result !== false; |
|
| 150 | - } else { |
|
| 151 | - return false; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * set the email address of the user |
|
| 157 | - * |
|
| 158 | - * @param string|null $mailAddress |
|
| 159 | - * @return void |
|
| 160 | - * @since 9.0.0 |
|
| 161 | - */ |
|
| 162 | - public function setEMailAddress($mailAddress) { |
|
| 163 | - $oldMailAddress = $this->getEMailAddress(); |
|
| 164 | - if($mailAddress === '') { |
|
| 165 | - $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
| 166 | - } else { |
|
| 167 | - $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
| 168 | - } |
|
| 169 | - if($oldMailAddress !== $mailAddress) { |
|
| 170 | - $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
| 176 | - * login |
|
| 177 | - * |
|
| 178 | - * @return int |
|
| 179 | - */ |
|
| 180 | - public function getLastLogin() { |
|
| 181 | - return $this->lastLogin; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * updates the timestamp of the most recent login of this user |
|
| 186 | - */ |
|
| 187 | - public function updateLastLoginTimestamp() { |
|
| 188 | - $firstTimeLogin = ($this->lastLogin === 0); |
|
| 189 | - $this->lastLogin = time(); |
|
| 190 | - $this->config->setUserValue( |
|
| 191 | - $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 192 | - |
|
| 193 | - return $firstTimeLogin; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Delete the user |
|
| 198 | - * |
|
| 199 | - * @return bool |
|
| 200 | - */ |
|
| 201 | - public function delete() { |
|
| 202 | - if ($this->emitter) { |
|
| 203 | - $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 204 | - } |
|
| 205 | - // get the home now because it won't return it after user deletion |
|
| 206 | - $homePath = $this->getHome(); |
|
| 207 | - $result = $this->backend->deleteUser($this->uid); |
|
| 208 | - if ($result) { |
|
| 209 | - |
|
| 210 | - // FIXME: Feels like an hack - suggestions? |
|
| 211 | - |
|
| 212 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 213 | - // We have to delete the user from all groups |
|
| 214 | - foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 215 | - $group = $groupManager->get($groupId); |
|
| 216 | - if ($group) { |
|
| 217 | - \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 218 | - $group->removeUser($this); |
|
| 219 | - \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - // Delete the user's keys in preferences |
|
| 223 | - \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 224 | - |
|
| 225 | - // Delete user files in /data/ |
|
| 226 | - if ($homePath !== false) { |
|
| 227 | - // FIXME: this operates directly on FS, should use View instead... |
|
| 228 | - // also this is not testable/mockable... |
|
| 229 | - \OC_Helper::rmdirr($homePath); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Delete the users entry in the storage table |
|
| 233 | - Storage::remove('home::' . $this->uid); |
|
| 234 | - |
|
| 235 | - \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 236 | - \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 237 | - |
|
| 238 | - $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 239 | - $notification->setUser($this->uid); |
|
| 240 | - \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 241 | - |
|
| 242 | - /** @var AccountManager $accountManager */ |
|
| 243 | - $accountManager = \OC::$server->query(AccountManager::class); |
|
| 244 | - $accountManager->deleteUser($this); |
|
| 245 | - |
|
| 246 | - if ($this->emitter) { |
|
| 247 | - $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - return !($result === false); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Set the password of the user |
|
| 255 | - * |
|
| 256 | - * @param string $password |
|
| 257 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 258 | - * @return bool |
|
| 259 | - */ |
|
| 260 | - public function setPassword($password, $recoveryPassword = null) { |
|
| 261 | - if ($this->emitter) { |
|
| 262 | - $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 263 | - } |
|
| 264 | - if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 265 | - $result = $this->backend->setPassword($this->uid, $password); |
|
| 266 | - if ($this->emitter) { |
|
| 267 | - $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 268 | - } |
|
| 269 | - return !($result === false); |
|
| 270 | - } else { |
|
| 271 | - return false; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * get the users home folder to mount |
|
| 277 | - * |
|
| 278 | - * @return string |
|
| 279 | - */ |
|
| 280 | - public function getHome() { |
|
| 281 | - if (!$this->home) { |
|
| 282 | - if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 283 | - $this->home = $home; |
|
| 284 | - } elseif ($this->config) { |
|
| 285 | - $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 286 | - } else { |
|
| 287 | - $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - return $this->home; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the name of the backend class the user is connected with |
|
| 295 | - * |
|
| 296 | - * @return string |
|
| 297 | - */ |
|
| 298 | - public function getBackendClassName() { |
|
| 299 | - if($this->backend instanceof IUserBackend) { |
|
| 300 | - return $this->backend->getBackendName(); |
|
| 301 | - } |
|
| 302 | - return get_class($this->backend); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - public function getBackend() { |
|
| 306 | - return $this->backend; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * check if the backend allows the user to change his avatar on Personal page |
|
| 311 | - * |
|
| 312 | - * @return bool |
|
| 313 | - */ |
|
| 314 | - public function canChangeAvatar() { |
|
| 315 | - if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 316 | - return $this->backend->canChangeAvatar($this->uid); |
|
| 317 | - } |
|
| 318 | - return true; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * check if the backend supports changing passwords |
|
| 323 | - * |
|
| 324 | - * @return bool |
|
| 325 | - */ |
|
| 326 | - public function canChangePassword() { |
|
| 327 | - return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * check if the backend supports changing display names |
|
| 332 | - * |
|
| 333 | - * @return bool |
|
| 334 | - */ |
|
| 335 | - public function canChangeDisplayName() { |
|
| 336 | - if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 337 | - return false; |
|
| 338 | - } |
|
| 339 | - return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * check if the user is enabled |
|
| 344 | - * |
|
| 345 | - * @return bool |
|
| 346 | - */ |
|
| 347 | - public function isEnabled() { |
|
| 348 | - return $this->enabled; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * set the enabled status for the user |
|
| 353 | - * |
|
| 354 | - * @param bool $enabled |
|
| 355 | - */ |
|
| 356 | - public function setEnabled(bool $enabled = true) { |
|
| 357 | - $oldStatus = $this->isEnabled(); |
|
| 358 | - $this->enabled = $enabled; |
|
| 359 | - if ($oldStatus !== $this->enabled) { |
|
| 360 | - $this->triggerChange('enabled', $enabled); |
|
| 361 | - $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false'); |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * get the users email address |
|
| 367 | - * |
|
| 368 | - * @return string|null |
|
| 369 | - * @since 9.0.0 |
|
| 370 | - */ |
|
| 371 | - public function getEMailAddress() { |
|
| 372 | - return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * get the users' quota |
|
| 377 | - * |
|
| 378 | - * @return string |
|
| 379 | - * @since 9.0.0 |
|
| 380 | - */ |
|
| 381 | - public function getQuota() { |
|
| 382 | - $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 383 | - if($quota === 'default') { |
|
| 384 | - $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 385 | - } |
|
| 386 | - return $quota; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * set the users' quota |
|
| 391 | - * |
|
| 392 | - * @param string $quota |
|
| 393 | - * @return void |
|
| 394 | - * @since 9.0.0 |
|
| 395 | - */ |
|
| 396 | - public function setQuota($quota) { |
|
| 397 | - $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
|
| 398 | - if($quota !== 'none' and $quota !== 'default') { |
|
| 399 | - $quota = OC_Helper::computerFileSize($quota); |
|
| 400 | - $quota = OC_Helper::humanFileSize($quota); |
|
| 401 | - } |
|
| 402 | - $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 403 | - if($quota !== $oldQuota) { |
|
| 404 | - $this->triggerChange('quota', $quota); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * get the avatar image if it exists |
|
| 410 | - * |
|
| 411 | - * @param int $size |
|
| 412 | - * @return IImage|null |
|
| 413 | - * @since 9.0.0 |
|
| 414 | - */ |
|
| 415 | - public function getAvatarImage($size) { |
|
| 416 | - // delay the initialization |
|
| 417 | - if (is_null($this->avatarManager)) { |
|
| 418 | - $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 422 | - $image = $avatar->get(-1); |
|
| 423 | - if ($image) { |
|
| 424 | - return $image; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return null; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * get the federation cloud id |
|
| 432 | - * |
|
| 433 | - * @return string |
|
| 434 | - * @since 9.0.0 |
|
| 435 | - */ |
|
| 436 | - public function getCloudId() { |
|
| 437 | - $uid = $this->getUID(); |
|
| 438 | - $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 439 | - $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 440 | - return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * @param string $url |
|
| 445 | - * @return string |
|
| 446 | - */ |
|
| 447 | - private function removeProtocolFromUrl($url) { |
|
| 448 | - if (strpos($url, 'https://') === 0) { |
|
| 449 | - return substr($url, strlen('https://')); |
|
| 450 | - } else if (strpos($url, 'http://') === 0) { |
|
| 451 | - return substr($url, strlen('http://')); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return $url; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 458 | - if ($this->emitter) { |
|
| 459 | - $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 460 | - } |
|
| 461 | - } |
|
| 47 | + /** @var string $uid */ |
|
| 48 | + private $uid; |
|
| 49 | + |
|
| 50 | + /** @var string $displayName */ |
|
| 51 | + private $displayName; |
|
| 52 | + |
|
| 53 | + /** @var UserInterface $backend */ |
|
| 54 | + private $backend; |
|
| 55 | + |
|
| 56 | + /** @var bool $enabled */ |
|
| 57 | + private $enabled; |
|
| 58 | + |
|
| 59 | + /** @var Emitter|Manager $emitter */ |
|
| 60 | + private $emitter; |
|
| 61 | + |
|
| 62 | + /** @var string $home */ |
|
| 63 | + private $home; |
|
| 64 | + |
|
| 65 | + /** @var int $lastLogin */ |
|
| 66 | + private $lastLogin; |
|
| 67 | + |
|
| 68 | + /** @var \OCP\IConfig $config */ |
|
| 69 | + private $config; |
|
| 70 | + |
|
| 71 | + /** @var IAvatarManager */ |
|
| 72 | + private $avatarManager; |
|
| 73 | + |
|
| 74 | + /** @var IURLGenerator */ |
|
| 75 | + private $urlGenerator; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $uid |
|
| 79 | + * @param UserInterface $backend |
|
| 80 | + * @param \OC\Hooks\Emitter $emitter |
|
| 81 | + * @param IConfig|null $config |
|
| 82 | + * @param IURLGenerator $urlGenerator |
|
| 83 | + */ |
|
| 84 | + public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
| 85 | + $this->uid = $uid; |
|
| 86 | + $this->backend = $backend; |
|
| 87 | + $this->emitter = $emitter; |
|
| 88 | + if(is_null($config)) { |
|
| 89 | + $config = \OC::$server->getConfig(); |
|
| 90 | + } |
|
| 91 | + $this->config = $config; |
|
| 92 | + $this->urlGenerator = $urlGenerator; |
|
| 93 | + $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
| 94 | + $this->enabled = ($enabled === 'true'); |
|
| 95 | + $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
| 96 | + if (is_null($this->urlGenerator)) { |
|
| 97 | + $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * get the user id |
|
| 103 | + * |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + public function getUID() { |
|
| 107 | + return $this->uid; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function getDisplayName() { |
|
| 116 | + if (!isset($this->displayName)) { |
|
| 117 | + $displayName = ''; |
|
| 118 | + if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
| 119 | + // get display name and strip whitespace from the beginning and end of it |
|
| 120 | + $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
| 121 | + if (is_string($backendDisplayName)) { |
|
| 122 | + $displayName = trim($backendDisplayName); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!empty($displayName)) { |
|
| 127 | + $this->displayName = $displayName; |
|
| 128 | + } else { |
|
| 129 | + $this->displayName = $this->uid; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $this->displayName; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * set the displayname for the user |
|
| 137 | + * |
|
| 138 | + * @param string $displayName |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + public function setDisplayName($displayName) { |
|
| 142 | + $displayName = trim($displayName); |
|
| 143 | + if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
| 144 | + $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
| 145 | + if ($result) { |
|
| 146 | + $this->displayName = $displayName; |
|
| 147 | + $this->triggerChange('displayName', $displayName); |
|
| 148 | + } |
|
| 149 | + return $result !== false; |
|
| 150 | + } else { |
|
| 151 | + return false; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * set the email address of the user |
|
| 157 | + * |
|
| 158 | + * @param string|null $mailAddress |
|
| 159 | + * @return void |
|
| 160 | + * @since 9.0.0 |
|
| 161 | + */ |
|
| 162 | + public function setEMailAddress($mailAddress) { |
|
| 163 | + $oldMailAddress = $this->getEMailAddress(); |
|
| 164 | + if($mailAddress === '') { |
|
| 165 | + $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
| 166 | + } else { |
|
| 167 | + $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
| 168 | + } |
|
| 169 | + if($oldMailAddress !== $mailAddress) { |
|
| 170 | + $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
| 176 | + * login |
|
| 177 | + * |
|
| 178 | + * @return int |
|
| 179 | + */ |
|
| 180 | + public function getLastLogin() { |
|
| 181 | + return $this->lastLogin; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * updates the timestamp of the most recent login of this user |
|
| 186 | + */ |
|
| 187 | + public function updateLastLoginTimestamp() { |
|
| 188 | + $firstTimeLogin = ($this->lastLogin === 0); |
|
| 189 | + $this->lastLogin = time(); |
|
| 190 | + $this->config->setUserValue( |
|
| 191 | + $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 192 | + |
|
| 193 | + return $firstTimeLogin; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Delete the user |
|
| 198 | + * |
|
| 199 | + * @return bool |
|
| 200 | + */ |
|
| 201 | + public function delete() { |
|
| 202 | + if ($this->emitter) { |
|
| 203 | + $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 204 | + } |
|
| 205 | + // get the home now because it won't return it after user deletion |
|
| 206 | + $homePath = $this->getHome(); |
|
| 207 | + $result = $this->backend->deleteUser($this->uid); |
|
| 208 | + if ($result) { |
|
| 209 | + |
|
| 210 | + // FIXME: Feels like an hack - suggestions? |
|
| 211 | + |
|
| 212 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 213 | + // We have to delete the user from all groups |
|
| 214 | + foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 215 | + $group = $groupManager->get($groupId); |
|
| 216 | + if ($group) { |
|
| 217 | + \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 218 | + $group->removeUser($this); |
|
| 219 | + \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + // Delete the user's keys in preferences |
|
| 223 | + \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 224 | + |
|
| 225 | + // Delete user files in /data/ |
|
| 226 | + if ($homePath !== false) { |
|
| 227 | + // FIXME: this operates directly on FS, should use View instead... |
|
| 228 | + // also this is not testable/mockable... |
|
| 229 | + \OC_Helper::rmdirr($homePath); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Delete the users entry in the storage table |
|
| 233 | + Storage::remove('home::' . $this->uid); |
|
| 234 | + |
|
| 235 | + \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 236 | + \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 237 | + |
|
| 238 | + $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 239 | + $notification->setUser($this->uid); |
|
| 240 | + \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 241 | + |
|
| 242 | + /** @var AccountManager $accountManager */ |
|
| 243 | + $accountManager = \OC::$server->query(AccountManager::class); |
|
| 244 | + $accountManager->deleteUser($this); |
|
| 245 | + |
|
| 246 | + if ($this->emitter) { |
|
| 247 | + $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + return !($result === false); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Set the password of the user |
|
| 255 | + * |
|
| 256 | + * @param string $password |
|
| 257 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 258 | + * @return bool |
|
| 259 | + */ |
|
| 260 | + public function setPassword($password, $recoveryPassword = null) { |
|
| 261 | + if ($this->emitter) { |
|
| 262 | + $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 263 | + } |
|
| 264 | + if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 265 | + $result = $this->backend->setPassword($this->uid, $password); |
|
| 266 | + if ($this->emitter) { |
|
| 267 | + $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 268 | + } |
|
| 269 | + return !($result === false); |
|
| 270 | + } else { |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * get the users home folder to mount |
|
| 277 | + * |
|
| 278 | + * @return string |
|
| 279 | + */ |
|
| 280 | + public function getHome() { |
|
| 281 | + if (!$this->home) { |
|
| 282 | + if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 283 | + $this->home = $home; |
|
| 284 | + } elseif ($this->config) { |
|
| 285 | + $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 286 | + } else { |
|
| 287 | + $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + return $this->home; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the name of the backend class the user is connected with |
|
| 295 | + * |
|
| 296 | + * @return string |
|
| 297 | + */ |
|
| 298 | + public function getBackendClassName() { |
|
| 299 | + if($this->backend instanceof IUserBackend) { |
|
| 300 | + return $this->backend->getBackendName(); |
|
| 301 | + } |
|
| 302 | + return get_class($this->backend); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + public function getBackend() { |
|
| 306 | + return $this->backend; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * check if the backend allows the user to change his avatar on Personal page |
|
| 311 | + * |
|
| 312 | + * @return bool |
|
| 313 | + */ |
|
| 314 | + public function canChangeAvatar() { |
|
| 315 | + if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 316 | + return $this->backend->canChangeAvatar($this->uid); |
|
| 317 | + } |
|
| 318 | + return true; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * check if the backend supports changing passwords |
|
| 323 | + * |
|
| 324 | + * @return bool |
|
| 325 | + */ |
|
| 326 | + public function canChangePassword() { |
|
| 327 | + return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * check if the backend supports changing display names |
|
| 332 | + * |
|
| 333 | + * @return bool |
|
| 334 | + */ |
|
| 335 | + public function canChangeDisplayName() { |
|
| 336 | + if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 339 | + return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * check if the user is enabled |
|
| 344 | + * |
|
| 345 | + * @return bool |
|
| 346 | + */ |
|
| 347 | + public function isEnabled() { |
|
| 348 | + return $this->enabled; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * set the enabled status for the user |
|
| 353 | + * |
|
| 354 | + * @param bool $enabled |
|
| 355 | + */ |
|
| 356 | + public function setEnabled(bool $enabled = true) { |
|
| 357 | + $oldStatus = $this->isEnabled(); |
|
| 358 | + $this->enabled = $enabled; |
|
| 359 | + if ($oldStatus !== $this->enabled) { |
|
| 360 | + $this->triggerChange('enabled', $enabled); |
|
| 361 | + $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false'); |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * get the users email address |
|
| 367 | + * |
|
| 368 | + * @return string|null |
|
| 369 | + * @since 9.0.0 |
|
| 370 | + */ |
|
| 371 | + public function getEMailAddress() { |
|
| 372 | + return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * get the users' quota |
|
| 377 | + * |
|
| 378 | + * @return string |
|
| 379 | + * @since 9.0.0 |
|
| 380 | + */ |
|
| 381 | + public function getQuota() { |
|
| 382 | + $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 383 | + if($quota === 'default') { |
|
| 384 | + $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 385 | + } |
|
| 386 | + return $quota; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * set the users' quota |
|
| 391 | + * |
|
| 392 | + * @param string $quota |
|
| 393 | + * @return void |
|
| 394 | + * @since 9.0.0 |
|
| 395 | + */ |
|
| 396 | + public function setQuota($quota) { |
|
| 397 | + $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
|
| 398 | + if($quota !== 'none' and $quota !== 'default') { |
|
| 399 | + $quota = OC_Helper::computerFileSize($quota); |
|
| 400 | + $quota = OC_Helper::humanFileSize($quota); |
|
| 401 | + } |
|
| 402 | + $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 403 | + if($quota !== $oldQuota) { |
|
| 404 | + $this->triggerChange('quota', $quota); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * get the avatar image if it exists |
|
| 410 | + * |
|
| 411 | + * @param int $size |
|
| 412 | + * @return IImage|null |
|
| 413 | + * @since 9.0.0 |
|
| 414 | + */ |
|
| 415 | + public function getAvatarImage($size) { |
|
| 416 | + // delay the initialization |
|
| 417 | + if (is_null($this->avatarManager)) { |
|
| 418 | + $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 422 | + $image = $avatar->get(-1); |
|
| 423 | + if ($image) { |
|
| 424 | + return $image; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return null; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * get the federation cloud id |
|
| 432 | + * |
|
| 433 | + * @return string |
|
| 434 | + * @since 9.0.0 |
|
| 435 | + */ |
|
| 436 | + public function getCloudId() { |
|
| 437 | + $uid = $this->getUID(); |
|
| 438 | + $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 439 | + $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 440 | + return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * @param string $url |
|
| 445 | + * @return string |
|
| 446 | + */ |
|
| 447 | + private function removeProtocolFromUrl($url) { |
|
| 448 | + if (strpos($url, 'https://') === 0) { |
|
| 449 | + return substr($url, strlen('https://')); |
|
| 450 | + } else if (strpos($url, 'http://') === 0) { |
|
| 451 | + return substr($url, strlen('http://')); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return $url; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 458 | + if ($this->emitter) { |
|
| 459 | + $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | 462 | } |
@@ -32,60 +32,60 @@ |
||
| 32 | 32 | use OCP\User\Backend\IPasswordConfirmationBackend; |
| 33 | 33 | |
| 34 | 34 | class PasswordConfirmationMiddleware extends Middleware { |
| 35 | - /** @var ControllerMethodReflector */ |
|
| 36 | - private $reflector; |
|
| 37 | - /** @var ISession */ |
|
| 38 | - private $session; |
|
| 39 | - /** @var IUserSession */ |
|
| 40 | - private $userSession; |
|
| 41 | - /** @var ITimeFactory */ |
|
| 42 | - private $timeFactory; |
|
| 43 | - /** @var array */ |
|
| 44 | - private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
| 35 | + /** @var ControllerMethodReflector */ |
|
| 36 | + private $reflector; |
|
| 37 | + /** @var ISession */ |
|
| 38 | + private $session; |
|
| 39 | + /** @var IUserSession */ |
|
| 40 | + private $userSession; |
|
| 41 | + /** @var ITimeFactory */ |
|
| 42 | + private $timeFactory; |
|
| 43 | + /** @var array */ |
|
| 44 | + private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * PasswordConfirmationMiddleware constructor. |
|
| 48 | - * |
|
| 49 | - * @param ControllerMethodReflector $reflector |
|
| 50 | - * @param ISession $session |
|
| 51 | - * @param IUserSession $userSession |
|
| 52 | - * @param ITimeFactory $timeFactory |
|
| 53 | - */ |
|
| 54 | - public function __construct(ControllerMethodReflector $reflector, |
|
| 55 | - ISession $session, |
|
| 56 | - IUserSession $userSession, |
|
| 57 | - ITimeFactory $timeFactory) { |
|
| 58 | - $this->reflector = $reflector; |
|
| 59 | - $this->session = $session; |
|
| 60 | - $this->userSession = $userSession; |
|
| 61 | - $this->timeFactory = $timeFactory; |
|
| 62 | - } |
|
| 46 | + /** |
|
| 47 | + * PasswordConfirmationMiddleware constructor. |
|
| 48 | + * |
|
| 49 | + * @param ControllerMethodReflector $reflector |
|
| 50 | + * @param ISession $session |
|
| 51 | + * @param IUserSession $userSession |
|
| 52 | + * @param ITimeFactory $timeFactory |
|
| 53 | + */ |
|
| 54 | + public function __construct(ControllerMethodReflector $reflector, |
|
| 55 | + ISession $session, |
|
| 56 | + IUserSession $userSession, |
|
| 57 | + ITimeFactory $timeFactory) { |
|
| 58 | + $this->reflector = $reflector; |
|
| 59 | + $this->session = $session; |
|
| 60 | + $this->userSession = $userSession; |
|
| 61 | + $this->timeFactory = $timeFactory; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param Controller $controller |
|
| 66 | - * @param string $methodName |
|
| 67 | - * @throws NotConfirmedException |
|
| 68 | - */ |
|
| 69 | - public function beforeController($controller, $methodName) { |
|
| 70 | - if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
| 71 | - $user = $this->userSession->getUser(); |
|
| 72 | - $backendClassName = ''; |
|
| 73 | - if ($user !== null) { |
|
| 74 | - $backend = $user->getBackend(); |
|
| 75 | - if ($backend instanceof IPasswordConfirmationBackend) { |
|
| 76 | - if (!$backend->canConfirmPassword($user->getUID())) { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 79 | - } |
|
| 64 | + /** |
|
| 65 | + * @param Controller $controller |
|
| 66 | + * @param string $methodName |
|
| 67 | + * @throws NotConfirmedException |
|
| 68 | + */ |
|
| 69 | + public function beforeController($controller, $methodName) { |
|
| 70 | + if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
| 71 | + $user = $this->userSession->getUser(); |
|
| 72 | + $backendClassName = ''; |
|
| 73 | + if ($user !== null) { |
|
| 74 | + $backend = $user->getBackend(); |
|
| 75 | + if ($backend instanceof IPasswordConfirmationBackend) { |
|
| 76 | + if (!$backend->canConfirmPassword($user->getUID())) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $backendClassName = $user->getBackendClassName(); |
|
| 82 | - } |
|
| 81 | + $backendClassName = $user->getBackendClassName(); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
| 85 | - // we can't check the password against a SAML backend, so skip password confirmation in this case |
|
| 86 | - if (!isset($this->excludedUserBackEnds[$backendClassName]) && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
| 87 | - throw new NotConfirmedException(); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 84 | + $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
| 85 | + // we can't check the password against a SAML backend, so skip password confirmation in this case |
|
| 86 | + if (!isset($this->excludedUserBackEnds[$backendClassName]) && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
| 87 | + throw new NotConfirmedException(); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -41,258 +41,258 @@ |
||
| 41 | 41 | |
| 42 | 42 | class JSConfigHelper { |
| 43 | 43 | |
| 44 | - /** @var IL10N */ |
|
| 45 | - private $l; |
|
| 44 | + /** @var IL10N */ |
|
| 45 | + private $l; |
|
| 46 | 46 | |
| 47 | - /** @var Defaults */ |
|
| 48 | - private $defaults; |
|
| 47 | + /** @var Defaults */ |
|
| 48 | + private $defaults; |
|
| 49 | 49 | |
| 50 | - /** @var IAppManager */ |
|
| 51 | - private $appManager; |
|
| 50 | + /** @var IAppManager */ |
|
| 51 | + private $appManager; |
|
| 52 | 52 | |
| 53 | - /** @var ISession */ |
|
| 54 | - private $session; |
|
| 53 | + /** @var ISession */ |
|
| 54 | + private $session; |
|
| 55 | 55 | |
| 56 | - /** @var IUser|null */ |
|
| 57 | - private $currentUser; |
|
| 56 | + /** @var IUser|null */ |
|
| 57 | + private $currentUser; |
|
| 58 | 58 | |
| 59 | - /** @var IConfig */ |
|
| 60 | - private $config; |
|
| 59 | + /** @var IConfig */ |
|
| 60 | + private $config; |
|
| 61 | 61 | |
| 62 | - /** @var IGroupManager */ |
|
| 63 | - private $groupManager; |
|
| 62 | + /** @var IGroupManager */ |
|
| 63 | + private $groupManager; |
|
| 64 | 64 | |
| 65 | - /** @var IniGetWrapper */ |
|
| 66 | - private $iniWrapper; |
|
| 65 | + /** @var IniGetWrapper */ |
|
| 66 | + private $iniWrapper; |
|
| 67 | 67 | |
| 68 | - /** @var IURLGenerator */ |
|
| 69 | - private $urlGenerator; |
|
| 68 | + /** @var IURLGenerator */ |
|
| 69 | + private $urlGenerator; |
|
| 70 | 70 | |
| 71 | - /** @var CapabilitiesManager */ |
|
| 72 | - private $capabilitiesManager; |
|
| 71 | + /** @var CapabilitiesManager */ |
|
| 72 | + private $capabilitiesManager; |
|
| 73 | 73 | |
| 74 | - /** @var array user back-ends excluded from password verification */ |
|
| 75 | - private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
| 74 | + /** @var array user back-ends excluded from password verification */ |
|
| 75 | + private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param IL10N $l |
|
| 79 | - * @param Defaults $defaults |
|
| 80 | - * @param IAppManager $appManager |
|
| 81 | - * @param ISession $session |
|
| 82 | - * @param IUser|null $currentUser |
|
| 83 | - * @param IConfig $config |
|
| 84 | - * @param IGroupManager $groupManager |
|
| 85 | - * @param IniGetWrapper $iniWrapper |
|
| 86 | - * @param IURLGenerator $urlGenerator |
|
| 87 | - * @param CapabilitiesManager $capabilitiesManager |
|
| 88 | - */ |
|
| 89 | - public function __construct(IL10N $l, |
|
| 90 | - Defaults $defaults, |
|
| 91 | - IAppManager $appManager, |
|
| 92 | - ISession $session, |
|
| 93 | - $currentUser, |
|
| 94 | - IConfig $config, |
|
| 95 | - IGroupManager $groupManager, |
|
| 96 | - IniGetWrapper $iniWrapper, |
|
| 97 | - IURLGenerator $urlGenerator, |
|
| 98 | - CapabilitiesManager $capabilitiesManager) { |
|
| 99 | - $this->l = $l; |
|
| 100 | - $this->defaults = $defaults; |
|
| 101 | - $this->appManager = $appManager; |
|
| 102 | - $this->session = $session; |
|
| 103 | - $this->currentUser = $currentUser; |
|
| 104 | - $this->config = $config; |
|
| 105 | - $this->groupManager = $groupManager; |
|
| 106 | - $this->iniWrapper = $iniWrapper; |
|
| 107 | - $this->urlGenerator = $urlGenerator; |
|
| 108 | - $this->capabilitiesManager = $capabilitiesManager; |
|
| 109 | - } |
|
| 77 | + /** |
|
| 78 | + * @param IL10N $l |
|
| 79 | + * @param Defaults $defaults |
|
| 80 | + * @param IAppManager $appManager |
|
| 81 | + * @param ISession $session |
|
| 82 | + * @param IUser|null $currentUser |
|
| 83 | + * @param IConfig $config |
|
| 84 | + * @param IGroupManager $groupManager |
|
| 85 | + * @param IniGetWrapper $iniWrapper |
|
| 86 | + * @param IURLGenerator $urlGenerator |
|
| 87 | + * @param CapabilitiesManager $capabilitiesManager |
|
| 88 | + */ |
|
| 89 | + public function __construct(IL10N $l, |
|
| 90 | + Defaults $defaults, |
|
| 91 | + IAppManager $appManager, |
|
| 92 | + ISession $session, |
|
| 93 | + $currentUser, |
|
| 94 | + IConfig $config, |
|
| 95 | + IGroupManager $groupManager, |
|
| 96 | + IniGetWrapper $iniWrapper, |
|
| 97 | + IURLGenerator $urlGenerator, |
|
| 98 | + CapabilitiesManager $capabilitiesManager) { |
|
| 99 | + $this->l = $l; |
|
| 100 | + $this->defaults = $defaults; |
|
| 101 | + $this->appManager = $appManager; |
|
| 102 | + $this->session = $session; |
|
| 103 | + $this->currentUser = $currentUser; |
|
| 104 | + $this->config = $config; |
|
| 105 | + $this->groupManager = $groupManager; |
|
| 106 | + $this->iniWrapper = $iniWrapper; |
|
| 107 | + $this->urlGenerator = $urlGenerator; |
|
| 108 | + $this->capabilitiesManager = $capabilitiesManager; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function getConfig() { |
|
| 111 | + public function getConfig() { |
|
| 112 | 112 | |
| 113 | - $userBackendAllowsPasswordConfirmation = true; |
|
| 114 | - if ($this->currentUser !== null) { |
|
| 115 | - $uid = $this->currentUser->getUID(); |
|
| 113 | + $userBackendAllowsPasswordConfirmation = true; |
|
| 114 | + if ($this->currentUser !== null) { |
|
| 115 | + $uid = $this->currentUser->getUID(); |
|
| 116 | 116 | |
| 117 | - $backend = $this->currentUser->getBackend(); |
|
| 118 | - if ($backend instanceof IPasswordConfirmationBackend) { |
|
| 119 | - $userBackendAllowsPasswordConfirmation = $backend->canConfirmPassword($uid); |
|
| 120 | - } else if (isset($this->excludedUserBackEnds[$this->currentUser->getBackendClassName()])) { |
|
| 121 | - $userBackendAllowsPasswordConfirmation = false; |
|
| 122 | - } |
|
| 123 | - } else { |
|
| 124 | - $uid = null; |
|
| 125 | - } |
|
| 117 | + $backend = $this->currentUser->getBackend(); |
|
| 118 | + if ($backend instanceof IPasswordConfirmationBackend) { |
|
| 119 | + $userBackendAllowsPasswordConfirmation = $backend->canConfirmPassword($uid); |
|
| 120 | + } else if (isset($this->excludedUserBackEnds[$this->currentUser->getBackendClassName()])) { |
|
| 121 | + $userBackendAllowsPasswordConfirmation = false; |
|
| 122 | + } |
|
| 123 | + } else { |
|
| 124 | + $uid = null; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - // Get the config |
|
| 128 | - $apps_paths = []; |
|
| 127 | + // Get the config |
|
| 128 | + $apps_paths = []; |
|
| 129 | 129 | |
| 130 | - if ($this->currentUser === null) { |
|
| 131 | - $apps = $this->appManager->getInstalledApps(); |
|
| 132 | - } else { |
|
| 133 | - $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
| 134 | - } |
|
| 130 | + if ($this->currentUser === null) { |
|
| 131 | + $apps = $this->appManager->getInstalledApps(); |
|
| 132 | + } else { |
|
| 133 | + $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - foreach($apps as $app) { |
|
| 137 | - $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
| 138 | - } |
|
| 136 | + foreach($apps as $app) { |
|
| 137 | + $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | - $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
| 142 | - $enableLinkPasswordByDefault = $enableLinkPasswordByDefault === 'yes'; |
|
| 143 | - $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 144 | - $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
| 145 | - if ($defaultExpireDateEnabled) { |
|
| 146 | - $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 147 | - $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 148 | - } |
|
| 149 | - $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 141 | + $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
| 142 | + $enableLinkPasswordByDefault = $enableLinkPasswordByDefault === 'yes'; |
|
| 143 | + $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 144 | + $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
| 145 | + if ($defaultExpireDateEnabled) { |
|
| 146 | + $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 147 | + $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 148 | + } |
|
| 149 | + $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 150 | 150 | |
| 151 | - $countOfDataLocation = 0; |
|
| 152 | - $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 153 | - if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 154 | - $dataLocation = false; |
|
| 155 | - } |
|
| 151 | + $countOfDataLocation = 0; |
|
| 152 | + $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 153 | + if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 154 | + $dataLocation = false; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - if ($this->currentUser instanceof IUser) { |
|
| 158 | - $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
| 159 | - if (!is_int($lastConfirmTimestamp)) { |
|
| 160 | - $lastConfirmTimestamp = 0; |
|
| 161 | - } |
|
| 162 | - } else { |
|
| 163 | - $lastConfirmTimestamp = 0; |
|
| 164 | - } |
|
| 157 | + if ($this->currentUser instanceof IUser) { |
|
| 158 | + $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
| 159 | + if (!is_int($lastConfirmTimestamp)) { |
|
| 160 | + $lastConfirmTimestamp = 0; |
|
| 161 | + } |
|
| 162 | + } else { |
|
| 163 | + $lastConfirmTimestamp = 0; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
| 166 | + $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
| 167 | 167 | |
| 168 | - $array = [ |
|
| 169 | - "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
| 170 | - "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
| 171 | - "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', |
|
| 172 | - "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
| 173 | - "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
| 174 | - "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
| 175 | - "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
| 176 | - 'nc_lastLogin' => $lastConfirmTimestamp, |
|
| 177 | - 'nc_pageLoad' => time(), |
|
| 178 | - "dayNames" => json_encode([ |
|
| 179 | - (string)$this->l->t('Sunday'), |
|
| 180 | - (string)$this->l->t('Monday'), |
|
| 181 | - (string)$this->l->t('Tuesday'), |
|
| 182 | - (string)$this->l->t('Wednesday'), |
|
| 183 | - (string)$this->l->t('Thursday'), |
|
| 184 | - (string)$this->l->t('Friday'), |
|
| 185 | - (string)$this->l->t('Saturday') |
|
| 186 | - ]), |
|
| 187 | - "dayNamesShort" => json_encode([ |
|
| 188 | - (string)$this->l->t('Sun.'), |
|
| 189 | - (string)$this->l->t('Mon.'), |
|
| 190 | - (string)$this->l->t('Tue.'), |
|
| 191 | - (string)$this->l->t('Wed.'), |
|
| 192 | - (string)$this->l->t('Thu.'), |
|
| 193 | - (string)$this->l->t('Fri.'), |
|
| 194 | - (string)$this->l->t('Sat.') |
|
| 195 | - ]), |
|
| 196 | - "dayNamesMin" => json_encode([ |
|
| 197 | - (string)$this->l->t('Su'), |
|
| 198 | - (string)$this->l->t('Mo'), |
|
| 199 | - (string)$this->l->t('Tu'), |
|
| 200 | - (string)$this->l->t('We'), |
|
| 201 | - (string)$this->l->t('Th'), |
|
| 202 | - (string)$this->l->t('Fr'), |
|
| 203 | - (string)$this->l->t('Sa') |
|
| 204 | - ]), |
|
| 205 | - "monthNames" => json_encode([ |
|
| 206 | - (string)$this->l->t('January'), |
|
| 207 | - (string)$this->l->t('February'), |
|
| 208 | - (string)$this->l->t('March'), |
|
| 209 | - (string)$this->l->t('April'), |
|
| 210 | - (string)$this->l->t('May'), |
|
| 211 | - (string)$this->l->t('June'), |
|
| 212 | - (string)$this->l->t('July'), |
|
| 213 | - (string)$this->l->t('August'), |
|
| 214 | - (string)$this->l->t('September'), |
|
| 215 | - (string)$this->l->t('October'), |
|
| 216 | - (string)$this->l->t('November'), |
|
| 217 | - (string)$this->l->t('December') |
|
| 218 | - ]), |
|
| 219 | - "monthNamesShort" => json_encode([ |
|
| 220 | - (string)$this->l->t('Jan.'), |
|
| 221 | - (string)$this->l->t('Feb.'), |
|
| 222 | - (string)$this->l->t('Mar.'), |
|
| 223 | - (string)$this->l->t('Apr.'), |
|
| 224 | - (string)$this->l->t('May.'), |
|
| 225 | - (string)$this->l->t('Jun.'), |
|
| 226 | - (string)$this->l->t('Jul.'), |
|
| 227 | - (string)$this->l->t('Aug.'), |
|
| 228 | - (string)$this->l->t('Sep.'), |
|
| 229 | - (string)$this->l->t('Oct.'), |
|
| 230 | - (string)$this->l->t('Nov.'), |
|
| 231 | - (string)$this->l->t('Dec.') |
|
| 232 | - ]), |
|
| 233 | - "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
| 234 | - "oc_config" => json_encode([ |
|
| 235 | - 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
| 236 | - 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
| 237 | - 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 238 | - 'versionstring' => \OC_Util::getVersionString(), |
|
| 239 | - 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
| 240 | - 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
| 241 | - 'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true', |
|
| 242 | - 'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0), |
|
| 243 | - 'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0), |
|
| 244 | - 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
| 245 | - ]), |
|
| 246 | - "oc_appconfig" => json_encode([ |
|
| 247 | - 'core' => [ |
|
| 248 | - 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
| 249 | - 'defaultExpireDate' => $defaultExpireDate, |
|
| 250 | - 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
| 251 | - 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
| 252 | - 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
| 253 | - 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
| 254 | - 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
| 255 | - 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
| 256 | - 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
| 257 | - 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
| 258 | - ] |
|
| 259 | - ]), |
|
| 260 | - "oc_defaults" => json_encode([ |
|
| 261 | - 'entity' => $this->defaults->getEntity(), |
|
| 262 | - 'name' => $this->defaults->getName(), |
|
| 263 | - 'title' => $this->defaults->getTitle(), |
|
| 264 | - 'baseUrl' => $this->defaults->getBaseUrl(), |
|
| 265 | - 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
| 266 | - 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
| 267 | - 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
| 268 | - 'slogan' => $this->defaults->getSlogan(), |
|
| 269 | - 'logoClaim' => '', |
|
| 270 | - 'shortFooter' => $this->defaults->getShortFooter(), |
|
| 271 | - 'longFooter' => $this->defaults->getLongFooter(), |
|
| 272 | - 'folder' => \OC_Util::getTheme(), |
|
| 273 | - ]), |
|
| 274 | - "oc_capabilities" => json_encode($capabilities), |
|
| 275 | - ]; |
|
| 168 | + $array = [ |
|
| 169 | + "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
| 170 | + "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
| 171 | + "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', |
|
| 172 | + "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
| 173 | + "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
| 174 | + "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
| 175 | + "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
| 176 | + 'nc_lastLogin' => $lastConfirmTimestamp, |
|
| 177 | + 'nc_pageLoad' => time(), |
|
| 178 | + "dayNames" => json_encode([ |
|
| 179 | + (string)$this->l->t('Sunday'), |
|
| 180 | + (string)$this->l->t('Monday'), |
|
| 181 | + (string)$this->l->t('Tuesday'), |
|
| 182 | + (string)$this->l->t('Wednesday'), |
|
| 183 | + (string)$this->l->t('Thursday'), |
|
| 184 | + (string)$this->l->t('Friday'), |
|
| 185 | + (string)$this->l->t('Saturday') |
|
| 186 | + ]), |
|
| 187 | + "dayNamesShort" => json_encode([ |
|
| 188 | + (string)$this->l->t('Sun.'), |
|
| 189 | + (string)$this->l->t('Mon.'), |
|
| 190 | + (string)$this->l->t('Tue.'), |
|
| 191 | + (string)$this->l->t('Wed.'), |
|
| 192 | + (string)$this->l->t('Thu.'), |
|
| 193 | + (string)$this->l->t('Fri.'), |
|
| 194 | + (string)$this->l->t('Sat.') |
|
| 195 | + ]), |
|
| 196 | + "dayNamesMin" => json_encode([ |
|
| 197 | + (string)$this->l->t('Su'), |
|
| 198 | + (string)$this->l->t('Mo'), |
|
| 199 | + (string)$this->l->t('Tu'), |
|
| 200 | + (string)$this->l->t('We'), |
|
| 201 | + (string)$this->l->t('Th'), |
|
| 202 | + (string)$this->l->t('Fr'), |
|
| 203 | + (string)$this->l->t('Sa') |
|
| 204 | + ]), |
|
| 205 | + "monthNames" => json_encode([ |
|
| 206 | + (string)$this->l->t('January'), |
|
| 207 | + (string)$this->l->t('February'), |
|
| 208 | + (string)$this->l->t('March'), |
|
| 209 | + (string)$this->l->t('April'), |
|
| 210 | + (string)$this->l->t('May'), |
|
| 211 | + (string)$this->l->t('June'), |
|
| 212 | + (string)$this->l->t('July'), |
|
| 213 | + (string)$this->l->t('August'), |
|
| 214 | + (string)$this->l->t('September'), |
|
| 215 | + (string)$this->l->t('October'), |
|
| 216 | + (string)$this->l->t('November'), |
|
| 217 | + (string)$this->l->t('December') |
|
| 218 | + ]), |
|
| 219 | + "monthNamesShort" => json_encode([ |
|
| 220 | + (string)$this->l->t('Jan.'), |
|
| 221 | + (string)$this->l->t('Feb.'), |
|
| 222 | + (string)$this->l->t('Mar.'), |
|
| 223 | + (string)$this->l->t('Apr.'), |
|
| 224 | + (string)$this->l->t('May.'), |
|
| 225 | + (string)$this->l->t('Jun.'), |
|
| 226 | + (string)$this->l->t('Jul.'), |
|
| 227 | + (string)$this->l->t('Aug.'), |
|
| 228 | + (string)$this->l->t('Sep.'), |
|
| 229 | + (string)$this->l->t('Oct.'), |
|
| 230 | + (string)$this->l->t('Nov.'), |
|
| 231 | + (string)$this->l->t('Dec.') |
|
| 232 | + ]), |
|
| 233 | + "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
| 234 | + "oc_config" => json_encode([ |
|
| 235 | + 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
| 236 | + 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
| 237 | + 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 238 | + 'versionstring' => \OC_Util::getVersionString(), |
|
| 239 | + 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
| 240 | + 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
| 241 | + 'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true', |
|
| 242 | + 'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0), |
|
| 243 | + 'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0), |
|
| 244 | + 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
| 245 | + ]), |
|
| 246 | + "oc_appconfig" => json_encode([ |
|
| 247 | + 'core' => [ |
|
| 248 | + 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
| 249 | + 'defaultExpireDate' => $defaultExpireDate, |
|
| 250 | + 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
| 251 | + 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
| 252 | + 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
| 253 | + 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
| 254 | + 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
| 255 | + 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
| 256 | + 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
| 257 | + 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
| 258 | + ] |
|
| 259 | + ]), |
|
| 260 | + "oc_defaults" => json_encode([ |
|
| 261 | + 'entity' => $this->defaults->getEntity(), |
|
| 262 | + 'name' => $this->defaults->getName(), |
|
| 263 | + 'title' => $this->defaults->getTitle(), |
|
| 264 | + 'baseUrl' => $this->defaults->getBaseUrl(), |
|
| 265 | + 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
| 266 | + 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
| 267 | + 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
| 268 | + 'slogan' => $this->defaults->getSlogan(), |
|
| 269 | + 'logoClaim' => '', |
|
| 270 | + 'shortFooter' => $this->defaults->getShortFooter(), |
|
| 271 | + 'longFooter' => $this->defaults->getLongFooter(), |
|
| 272 | + 'folder' => \OC_Util::getTheme(), |
|
| 273 | + ]), |
|
| 274 | + "oc_capabilities" => json_encode($capabilities), |
|
| 275 | + ]; |
|
| 276 | 276 | |
| 277 | - if ($this->currentUser !== null) { |
|
| 278 | - $array['oc_userconfig'] = json_encode([ |
|
| 279 | - 'avatar' => [ |
|
| 280 | - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 281 | - 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', |
|
| 282 | - ] |
|
| 283 | - ]); |
|
| 284 | - } |
|
| 277 | + if ($this->currentUser !== null) { |
|
| 278 | + $array['oc_userconfig'] = json_encode([ |
|
| 279 | + 'avatar' => [ |
|
| 280 | + 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 281 | + 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', |
|
| 282 | + ] |
|
| 283 | + ]); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - // Allow hooks to modify the output values |
|
| 287 | - \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
| 286 | + // Allow hooks to modify the output values |
|
| 287 | + \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
| 288 | 288 | |
| 289 | - $result = ''; |
|
| 289 | + $result = ''; |
|
| 290 | 290 | |
| 291 | - // Echo it |
|
| 292 | - foreach ($array as $setting => $value) { |
|
| 293 | - $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
| 294 | - } |
|
| 291 | + // Echo it |
|
| 292 | + foreach ($array as $setting => $value) { |
|
| 293 | + $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - return $result; |
|
| 297 | - } |
|
| 296 | + return $result; |
|
| 297 | + } |
|
| 298 | 298 | } |
@@ -34,177 +34,177 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | interface IUser { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * get the user id |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - * @since 8.0.0 |
|
| 42 | - */ |
|
| 43 | - public function getUID(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - * @since 8.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getDisplayName(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * set the display name for the user |
|
| 55 | - * |
|
| 56 | - * @param string $displayName |
|
| 57 | - * @return bool |
|
| 58 | - * @since 8.0.0 |
|
| 59 | - */ |
|
| 60 | - public function setDisplayName($displayName); |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
| 64 | - * login |
|
| 65 | - * |
|
| 66 | - * @return int |
|
| 67 | - * @since 8.0.0 |
|
| 68 | - */ |
|
| 69 | - public function getLastLogin(); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * updates the timestamp of the most recent login of this user |
|
| 73 | - * @since 8.0.0 |
|
| 74 | - */ |
|
| 75 | - public function updateLastLoginTimestamp(); |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Delete the user |
|
| 79 | - * |
|
| 80 | - * @return bool |
|
| 81 | - * @since 8.0.0 |
|
| 82 | - */ |
|
| 83 | - public function delete(); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Set the password of the user |
|
| 87 | - * |
|
| 88 | - * @param string $password |
|
| 89 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 90 | - * @return bool |
|
| 91 | - * @since 8.0.0 |
|
| 92 | - */ |
|
| 93 | - public function setPassword($password, $recoveryPassword = null); |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * get the users home folder to mount |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - * @since 8.0.0 |
|
| 100 | - */ |
|
| 101 | - public function getHome(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Get the name of the backend class the user is connected with |
|
| 105 | - * |
|
| 106 | - * @return string |
|
| 107 | - * @since 8.0.0 |
|
| 108 | - */ |
|
| 109 | - public function getBackendClassName(); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Get the backend for the current user object |
|
| 113 | - * |
|
| 114 | - * @since 15.0.0 |
|
| 115 | - */ |
|
| 116 | - public function getBackend(); |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * check if the backend allows the user to change his avatar on Personal page |
|
| 120 | - * |
|
| 121 | - * @return bool |
|
| 122 | - * @since 8.0.0 |
|
| 123 | - */ |
|
| 124 | - public function canChangeAvatar(); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * check if the backend supports changing passwords |
|
| 128 | - * |
|
| 129 | - * @return bool |
|
| 130 | - * @since 8.0.0 |
|
| 131 | - */ |
|
| 132 | - public function canChangePassword(); |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * check if the backend supports changing display names |
|
| 136 | - * |
|
| 137 | - * @return bool |
|
| 138 | - * @since 8.0.0 |
|
| 139 | - */ |
|
| 140 | - public function canChangeDisplayName(); |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * check if the user is enabled |
|
| 144 | - * |
|
| 145 | - * @return bool |
|
| 146 | - * @since 8.0.0 |
|
| 147 | - */ |
|
| 148 | - public function isEnabled(); |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * set the enabled status for the user |
|
| 152 | - * |
|
| 153 | - * @param bool $enabled |
|
| 154 | - * @since 8.0.0 |
|
| 155 | - */ |
|
| 156 | - public function setEnabled(bool $enabled = true); |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * get the users email address |
|
| 160 | - * |
|
| 161 | - * @return string|null |
|
| 162 | - * @since 9.0.0 |
|
| 163 | - */ |
|
| 164 | - public function getEMailAddress(); |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * get the avatar image if it exists |
|
| 168 | - * |
|
| 169 | - * @param int $size |
|
| 170 | - * @return IImage|null |
|
| 171 | - * @since 9.0.0 |
|
| 172 | - */ |
|
| 173 | - public function getAvatarImage($size); |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * get the federation cloud id |
|
| 177 | - * |
|
| 178 | - * @return string |
|
| 179 | - * @since 9.0.0 |
|
| 180 | - */ |
|
| 181 | - public function getCloudId(); |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * set the email address of the user |
|
| 185 | - * |
|
| 186 | - * @param string|null $mailAddress |
|
| 187 | - * @return void |
|
| 188 | - * @since 9.0.0 |
|
| 189 | - */ |
|
| 190 | - public function setEMailAddress($mailAddress); |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * get the users' quota in human readable form. If a specific quota is not |
|
| 194 | - * set for the user, the default value is returned. If a default setting |
|
| 195 | - * was not set otherwise, it is return as 'none', i.e. quota is not limited. |
|
| 196 | - * |
|
| 197 | - * @return string |
|
| 198 | - * @since 9.0.0 |
|
| 199 | - */ |
|
| 200 | - public function getQuota(); |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * set the users' quota |
|
| 204 | - * |
|
| 205 | - * @param string $quota |
|
| 206 | - * @return void |
|
| 207 | - * @since 9.0.0 |
|
| 208 | - */ |
|
| 209 | - public function setQuota($quota); |
|
| 37 | + /** |
|
| 38 | + * get the user id |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + * @since 8.0.0 |
|
| 42 | + */ |
|
| 43 | + public function getUID(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + * @since 8.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getDisplayName(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * set the display name for the user |
|
| 55 | + * |
|
| 56 | + * @param string $displayName |
|
| 57 | + * @return bool |
|
| 58 | + * @since 8.0.0 |
|
| 59 | + */ |
|
| 60 | + public function setDisplayName($displayName); |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
| 64 | + * login |
|
| 65 | + * |
|
| 66 | + * @return int |
|
| 67 | + * @since 8.0.0 |
|
| 68 | + */ |
|
| 69 | + public function getLastLogin(); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * updates the timestamp of the most recent login of this user |
|
| 73 | + * @since 8.0.0 |
|
| 74 | + */ |
|
| 75 | + public function updateLastLoginTimestamp(); |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Delete the user |
|
| 79 | + * |
|
| 80 | + * @return bool |
|
| 81 | + * @since 8.0.0 |
|
| 82 | + */ |
|
| 83 | + public function delete(); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Set the password of the user |
|
| 87 | + * |
|
| 88 | + * @param string $password |
|
| 89 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 90 | + * @return bool |
|
| 91 | + * @since 8.0.0 |
|
| 92 | + */ |
|
| 93 | + public function setPassword($password, $recoveryPassword = null); |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * get the users home folder to mount |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + * @since 8.0.0 |
|
| 100 | + */ |
|
| 101 | + public function getHome(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Get the name of the backend class the user is connected with |
|
| 105 | + * |
|
| 106 | + * @return string |
|
| 107 | + * @since 8.0.0 |
|
| 108 | + */ |
|
| 109 | + public function getBackendClassName(); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Get the backend for the current user object |
|
| 113 | + * |
|
| 114 | + * @since 15.0.0 |
|
| 115 | + */ |
|
| 116 | + public function getBackend(); |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * check if the backend allows the user to change his avatar on Personal page |
|
| 120 | + * |
|
| 121 | + * @return bool |
|
| 122 | + * @since 8.0.0 |
|
| 123 | + */ |
|
| 124 | + public function canChangeAvatar(); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * check if the backend supports changing passwords |
|
| 128 | + * |
|
| 129 | + * @return bool |
|
| 130 | + * @since 8.0.0 |
|
| 131 | + */ |
|
| 132 | + public function canChangePassword(); |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * check if the backend supports changing display names |
|
| 136 | + * |
|
| 137 | + * @return bool |
|
| 138 | + * @since 8.0.0 |
|
| 139 | + */ |
|
| 140 | + public function canChangeDisplayName(); |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * check if the user is enabled |
|
| 144 | + * |
|
| 145 | + * @return bool |
|
| 146 | + * @since 8.0.0 |
|
| 147 | + */ |
|
| 148 | + public function isEnabled(); |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * set the enabled status for the user |
|
| 152 | + * |
|
| 153 | + * @param bool $enabled |
|
| 154 | + * @since 8.0.0 |
|
| 155 | + */ |
|
| 156 | + public function setEnabled(bool $enabled = true); |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * get the users email address |
|
| 160 | + * |
|
| 161 | + * @return string|null |
|
| 162 | + * @since 9.0.0 |
|
| 163 | + */ |
|
| 164 | + public function getEMailAddress(); |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * get the avatar image if it exists |
|
| 168 | + * |
|
| 169 | + * @param int $size |
|
| 170 | + * @return IImage|null |
|
| 171 | + * @since 9.0.0 |
|
| 172 | + */ |
|
| 173 | + public function getAvatarImage($size); |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * get the federation cloud id |
|
| 177 | + * |
|
| 178 | + * @return string |
|
| 179 | + * @since 9.0.0 |
|
| 180 | + */ |
|
| 181 | + public function getCloudId(); |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * set the email address of the user |
|
| 185 | + * |
|
| 186 | + * @param string|null $mailAddress |
|
| 187 | + * @return void |
|
| 188 | + * @since 9.0.0 |
|
| 189 | + */ |
|
| 190 | + public function setEMailAddress($mailAddress); |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * get the users' quota in human readable form. If a specific quota is not |
|
| 194 | + * set for the user, the default value is returned. If a default setting |
|
| 195 | + * was not set otherwise, it is return as 'none', i.e. quota is not limited. |
|
| 196 | + * |
|
| 197 | + * @return string |
|
| 198 | + * @since 9.0.0 |
|
| 199 | + */ |
|
| 200 | + public function getQuota(); |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * set the users' quota |
|
| 204 | + * |
|
| 205 | + * @param string $quota |
|
| 206 | + * @return void |
|
| 207 | + * @since 9.0.0 |
|
| 208 | + */ |
|
| 209 | + public function setQuota($quota); |
|
| 210 | 210 | } |
@@ -29,8 +29,8 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface IPasswordConfirmationBackend { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @since 15.0.0 |
|
| 34 | - */ |
|
| 35 | - public function canConfirmPassword(string $uid): bool; |
|
| 32 | + /** |
|
| 33 | + * @since 15.0.0 |
|
| 34 | + */ |
|
| 35 | + public function canConfirmPassword(string $uid): bool; |
|
| 36 | 36 | } |