@@ -43,411 +43,411 @@ |
||
| 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 | - $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
| 173 | - * login |
|
| 174 | - * |
|
| 175 | - * @return int |
|
| 176 | - */ |
|
| 177 | - public function getLastLogin() { |
|
| 178 | - return $this->lastLogin; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * updates the timestamp of the most recent login of this user |
|
| 183 | - */ |
|
| 184 | - public function updateLastLoginTimestamp() { |
|
| 185 | - $firstTimeLogin = ($this->lastLogin === 0); |
|
| 186 | - $this->lastLogin = time(); |
|
| 187 | - $this->config->setUserValue( |
|
| 188 | - $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 189 | - |
|
| 190 | - return $firstTimeLogin; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Delete the user |
|
| 195 | - * |
|
| 196 | - * @return bool |
|
| 197 | - */ |
|
| 198 | - public function delete() { |
|
| 199 | - if ($this->emitter) { |
|
| 200 | - $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 201 | - } |
|
| 202 | - // get the home now because it won't return it after user deletion |
|
| 203 | - $homePath = $this->getHome(); |
|
| 204 | - $result = $this->backend->deleteUser($this->uid); |
|
| 205 | - if ($result) { |
|
| 206 | - |
|
| 207 | - // FIXME: Feels like an hack - suggestions? |
|
| 208 | - |
|
| 209 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 210 | - // We have to delete the user from all groups |
|
| 211 | - foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 212 | - $group = $groupManager->get($groupId); |
|
| 213 | - if ($group) { |
|
| 214 | - \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 215 | - $group->removeUser($this); |
|
| 216 | - \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - // Delete the user's keys in preferences |
|
| 220 | - \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 221 | - |
|
| 222 | - // Delete user files in /data/ |
|
| 223 | - if ($homePath !== false) { |
|
| 224 | - // FIXME: this operates directly on FS, should use View instead... |
|
| 225 | - // also this is not testable/mockable... |
|
| 226 | - \OC_Helper::rmdirr($homePath); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Delete the users entry in the storage table |
|
| 230 | - Storage::remove('home::' . $this->uid); |
|
| 231 | - |
|
| 232 | - \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 233 | - \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 234 | - |
|
| 235 | - $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 236 | - $notification->setUser($this->uid); |
|
| 237 | - \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 238 | - |
|
| 239 | - /** @var AccountManager $accountManager */ |
|
| 240 | - $accountManager = \OC::$server->query(AccountManager::class); |
|
| 241 | - $accountManager->deleteUser($this); |
|
| 242 | - |
|
| 243 | - if ($this->emitter) { |
|
| 244 | - $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - return !($result === false); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Set the password of the user |
|
| 252 | - * |
|
| 253 | - * @param string $password |
|
| 254 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 255 | - * @return bool |
|
| 256 | - */ |
|
| 257 | - public function setPassword($password, $recoveryPassword = null) { |
|
| 258 | - if ($this->emitter) { |
|
| 259 | - $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 260 | - } |
|
| 261 | - if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 262 | - $result = $this->backend->setPassword($this->uid, $password); |
|
| 263 | - if ($this->emitter) { |
|
| 264 | - $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 265 | - } |
|
| 266 | - return !($result === false); |
|
| 267 | - } else { |
|
| 268 | - return false; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * get the users home folder to mount |
|
| 274 | - * |
|
| 275 | - * @return string |
|
| 276 | - */ |
|
| 277 | - public function getHome() { |
|
| 278 | - if (!$this->home) { |
|
| 279 | - if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 280 | - $this->home = $home; |
|
| 281 | - } elseif ($this->config) { |
|
| 282 | - $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 283 | - } else { |
|
| 284 | - $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - return $this->home; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Get the name of the backend class the user is connected with |
|
| 292 | - * |
|
| 293 | - * @return string |
|
| 294 | - */ |
|
| 295 | - public function getBackendClassName() { |
|
| 296 | - if($this->backend instanceof IUserBackend) { |
|
| 297 | - return $this->backend->getBackendName(); |
|
| 298 | - } |
|
| 299 | - return get_class($this->backend); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * check if the backend allows the user to change his avatar on Personal page |
|
| 304 | - * |
|
| 305 | - * @return bool |
|
| 306 | - */ |
|
| 307 | - public function canChangeAvatar() { |
|
| 308 | - if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 309 | - return $this->backend->canChangeAvatar($this->uid); |
|
| 310 | - } |
|
| 311 | - return true; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * check if the backend supports changing passwords |
|
| 316 | - * |
|
| 317 | - * @return bool |
|
| 318 | - */ |
|
| 319 | - public function canChangePassword() { |
|
| 320 | - return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * check if the backend supports changing display names |
|
| 325 | - * |
|
| 326 | - * @return bool |
|
| 327 | - */ |
|
| 328 | - public function canChangeDisplayName() { |
|
| 329 | - if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 330 | - return false; |
|
| 331 | - } |
|
| 332 | - return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * check if the user is enabled |
|
| 337 | - * |
|
| 338 | - * @return bool |
|
| 339 | - */ |
|
| 340 | - public function isEnabled() { |
|
| 341 | - return $this->enabled; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * set the enabled status for the user |
|
| 346 | - * |
|
| 347 | - * @param bool $enabled |
|
| 348 | - */ |
|
| 349 | - public function setEnabled($enabled) { |
|
| 350 | - $oldStatus = $this->isEnabled(); |
|
| 351 | - $this->enabled = $enabled; |
|
| 352 | - $enabled = ($enabled) ? 'true' : 'false'; |
|
| 353 | - if ($oldStatus !== $this->enabled) { |
|
| 354 | - $this->triggerChange('enabled', $enabled); |
|
| 355 | - $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * get the users email address |
|
| 361 | - * |
|
| 362 | - * @return string|null |
|
| 363 | - * @since 9.0.0 |
|
| 364 | - */ |
|
| 365 | - public function getEMailAddress() { |
|
| 366 | - return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * get the users' quota |
|
| 371 | - * |
|
| 372 | - * @return string |
|
| 373 | - * @since 9.0.0 |
|
| 374 | - */ |
|
| 375 | - public function getQuota() { |
|
| 376 | - $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 377 | - if($quota === 'default') { |
|
| 378 | - $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 379 | - } |
|
| 380 | - return $quota; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * set the users' quota |
|
| 385 | - * |
|
| 386 | - * @param string $quota |
|
| 387 | - * @return void |
|
| 388 | - * @since 9.0.0 |
|
| 389 | - */ |
|
| 390 | - public function setQuota($quota) { |
|
| 391 | - if($quota !== 'none' and $quota !== 'default') { |
|
| 392 | - $quota = OC_Helper::computerFileSize($quota); |
|
| 393 | - $quota = OC_Helper::humanFileSize($quota); |
|
| 394 | - } |
|
| 395 | - $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 396 | - $this->triggerChange('quota', $quota); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * get the avatar image if it exists |
|
| 401 | - * |
|
| 402 | - * @param int $size |
|
| 403 | - * @return IImage|null |
|
| 404 | - * @since 9.0.0 |
|
| 405 | - */ |
|
| 406 | - public function getAvatarImage($size) { |
|
| 407 | - // delay the initialization |
|
| 408 | - if (is_null($this->avatarManager)) { |
|
| 409 | - $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 413 | - $image = $avatar->get(-1); |
|
| 414 | - if ($image) { |
|
| 415 | - return $image; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - return null; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * get the federation cloud id |
|
| 423 | - * |
|
| 424 | - * @return string |
|
| 425 | - * @since 9.0.0 |
|
| 426 | - */ |
|
| 427 | - public function getCloudId() { |
|
| 428 | - $uid = $this->getUID(); |
|
| 429 | - $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 430 | - $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 431 | - return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * @param string $url |
|
| 436 | - * @return string |
|
| 437 | - */ |
|
| 438 | - private function removeProtocolFromUrl($url) { |
|
| 439 | - if (strpos($url, 'https://') === 0) { |
|
| 440 | - return substr($url, strlen('https://')); |
|
| 441 | - } else if (strpos($url, 'http://') === 0) { |
|
| 442 | - return substr($url, strlen('http://')); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - return $url; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 449 | - if ($this->emitter) { |
|
| 450 | - $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 451 | - } |
|
| 452 | - } |
|
| 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 | + $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
| 173 | + * login |
|
| 174 | + * |
|
| 175 | + * @return int |
|
| 176 | + */ |
|
| 177 | + public function getLastLogin() { |
|
| 178 | + return $this->lastLogin; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * updates the timestamp of the most recent login of this user |
|
| 183 | + */ |
|
| 184 | + public function updateLastLoginTimestamp() { |
|
| 185 | + $firstTimeLogin = ($this->lastLogin === 0); |
|
| 186 | + $this->lastLogin = time(); |
|
| 187 | + $this->config->setUserValue( |
|
| 188 | + $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 189 | + |
|
| 190 | + return $firstTimeLogin; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Delete the user |
|
| 195 | + * |
|
| 196 | + * @return bool |
|
| 197 | + */ |
|
| 198 | + public function delete() { |
|
| 199 | + if ($this->emitter) { |
|
| 200 | + $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 201 | + } |
|
| 202 | + // get the home now because it won't return it after user deletion |
|
| 203 | + $homePath = $this->getHome(); |
|
| 204 | + $result = $this->backend->deleteUser($this->uid); |
|
| 205 | + if ($result) { |
|
| 206 | + |
|
| 207 | + // FIXME: Feels like an hack - suggestions? |
|
| 208 | + |
|
| 209 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 210 | + // We have to delete the user from all groups |
|
| 211 | + foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 212 | + $group = $groupManager->get($groupId); |
|
| 213 | + if ($group) { |
|
| 214 | + \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 215 | + $group->removeUser($this); |
|
| 216 | + \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + // Delete the user's keys in preferences |
|
| 220 | + \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 221 | + |
|
| 222 | + // Delete user files in /data/ |
|
| 223 | + if ($homePath !== false) { |
|
| 224 | + // FIXME: this operates directly on FS, should use View instead... |
|
| 225 | + // also this is not testable/mockable... |
|
| 226 | + \OC_Helper::rmdirr($homePath); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Delete the users entry in the storage table |
|
| 230 | + Storage::remove('home::' . $this->uid); |
|
| 231 | + |
|
| 232 | + \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 233 | + \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 234 | + |
|
| 235 | + $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 236 | + $notification->setUser($this->uid); |
|
| 237 | + \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 238 | + |
|
| 239 | + /** @var AccountManager $accountManager */ |
|
| 240 | + $accountManager = \OC::$server->query(AccountManager::class); |
|
| 241 | + $accountManager->deleteUser($this); |
|
| 242 | + |
|
| 243 | + if ($this->emitter) { |
|
| 244 | + $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + return !($result === false); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Set the password of the user |
|
| 252 | + * |
|
| 253 | + * @param string $password |
|
| 254 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 255 | + * @return bool |
|
| 256 | + */ |
|
| 257 | + public function setPassword($password, $recoveryPassword = null) { |
|
| 258 | + if ($this->emitter) { |
|
| 259 | + $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 260 | + } |
|
| 261 | + if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 262 | + $result = $this->backend->setPassword($this->uid, $password); |
|
| 263 | + if ($this->emitter) { |
|
| 264 | + $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 265 | + } |
|
| 266 | + return !($result === false); |
|
| 267 | + } else { |
|
| 268 | + return false; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * get the users home folder to mount |
|
| 274 | + * |
|
| 275 | + * @return string |
|
| 276 | + */ |
|
| 277 | + public function getHome() { |
|
| 278 | + if (!$this->home) { |
|
| 279 | + if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 280 | + $this->home = $home; |
|
| 281 | + } elseif ($this->config) { |
|
| 282 | + $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 283 | + } else { |
|
| 284 | + $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + return $this->home; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Get the name of the backend class the user is connected with |
|
| 292 | + * |
|
| 293 | + * @return string |
|
| 294 | + */ |
|
| 295 | + public function getBackendClassName() { |
|
| 296 | + if($this->backend instanceof IUserBackend) { |
|
| 297 | + return $this->backend->getBackendName(); |
|
| 298 | + } |
|
| 299 | + return get_class($this->backend); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * check if the backend allows the user to change his avatar on Personal page |
|
| 304 | + * |
|
| 305 | + * @return bool |
|
| 306 | + */ |
|
| 307 | + public function canChangeAvatar() { |
|
| 308 | + if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 309 | + return $this->backend->canChangeAvatar($this->uid); |
|
| 310 | + } |
|
| 311 | + return true; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * check if the backend supports changing passwords |
|
| 316 | + * |
|
| 317 | + * @return bool |
|
| 318 | + */ |
|
| 319 | + public function canChangePassword() { |
|
| 320 | + return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * check if the backend supports changing display names |
|
| 325 | + * |
|
| 326 | + * @return bool |
|
| 327 | + */ |
|
| 328 | + public function canChangeDisplayName() { |
|
| 329 | + if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 330 | + return false; |
|
| 331 | + } |
|
| 332 | + return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * check if the user is enabled |
|
| 337 | + * |
|
| 338 | + * @return bool |
|
| 339 | + */ |
|
| 340 | + public function isEnabled() { |
|
| 341 | + return $this->enabled; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * set the enabled status for the user |
|
| 346 | + * |
|
| 347 | + * @param bool $enabled |
|
| 348 | + */ |
|
| 349 | + public function setEnabled($enabled) { |
|
| 350 | + $oldStatus = $this->isEnabled(); |
|
| 351 | + $this->enabled = $enabled; |
|
| 352 | + $enabled = ($enabled) ? 'true' : 'false'; |
|
| 353 | + if ($oldStatus !== $this->enabled) { |
|
| 354 | + $this->triggerChange('enabled', $enabled); |
|
| 355 | + $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * get the users email address |
|
| 361 | + * |
|
| 362 | + * @return string|null |
|
| 363 | + * @since 9.0.0 |
|
| 364 | + */ |
|
| 365 | + public function getEMailAddress() { |
|
| 366 | + return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * get the users' quota |
|
| 371 | + * |
|
| 372 | + * @return string |
|
| 373 | + * @since 9.0.0 |
|
| 374 | + */ |
|
| 375 | + public function getQuota() { |
|
| 376 | + $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 377 | + if($quota === 'default') { |
|
| 378 | + $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 379 | + } |
|
| 380 | + return $quota; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * set the users' quota |
|
| 385 | + * |
|
| 386 | + * @param string $quota |
|
| 387 | + * @return void |
|
| 388 | + * @since 9.0.0 |
|
| 389 | + */ |
|
| 390 | + public function setQuota($quota) { |
|
| 391 | + if($quota !== 'none' and $quota !== 'default') { |
|
| 392 | + $quota = OC_Helper::computerFileSize($quota); |
|
| 393 | + $quota = OC_Helper::humanFileSize($quota); |
|
| 394 | + } |
|
| 395 | + $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 396 | + $this->triggerChange('quota', $quota); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * get the avatar image if it exists |
|
| 401 | + * |
|
| 402 | + * @param int $size |
|
| 403 | + * @return IImage|null |
|
| 404 | + * @since 9.0.0 |
|
| 405 | + */ |
|
| 406 | + public function getAvatarImage($size) { |
|
| 407 | + // delay the initialization |
|
| 408 | + if (is_null($this->avatarManager)) { |
|
| 409 | + $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 413 | + $image = $avatar->get(-1); |
|
| 414 | + if ($image) { |
|
| 415 | + return $image; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + return null; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * get the federation cloud id |
|
| 423 | + * |
|
| 424 | + * @return string |
|
| 425 | + * @since 9.0.0 |
|
| 426 | + */ |
|
| 427 | + public function getCloudId() { |
|
| 428 | + $uid = $this->getUID(); |
|
| 429 | + $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 430 | + $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 431 | + return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * @param string $url |
|
| 436 | + * @return string |
|
| 437 | + */ |
|
| 438 | + private function removeProtocolFromUrl($url) { |
|
| 439 | + if (strpos($url, 'https://') === 0) { |
|
| 440 | + return substr($url, strlen('https://')); |
|
| 441 | + } else if (strpos($url, 'http://') === 0) { |
|
| 442 | + return substr($url, strlen('http://')); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + return $url; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 449 | + if ($this->emitter) { |
|
| 450 | + $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | 453 | } |
@@ -39,305 +39,305 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class AccountManager { |
| 41 | 41 | |
| 42 | - /** nobody can see my account details */ |
|
| 43 | - const VISIBILITY_PRIVATE = 'private'; |
|
| 44 | - /** only contacts, especially trusted servers can see my contact details */ |
|
| 45 | - const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 46 | - /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 47 | - const VISIBILITY_PUBLIC = 'public'; |
|
| 48 | - |
|
| 49 | - const PROPERTY_AVATAR = 'avatar'; |
|
| 50 | - const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 51 | - const PROPERTY_PHONE = 'phone'; |
|
| 52 | - const PROPERTY_EMAIL = 'email'; |
|
| 53 | - const PROPERTY_WEBSITE = 'website'; |
|
| 54 | - const PROPERTY_ADDRESS = 'address'; |
|
| 55 | - const PROPERTY_TWITTER = 'twitter'; |
|
| 56 | - |
|
| 57 | - const NOT_VERIFIED = '0'; |
|
| 58 | - const VERIFICATION_IN_PROGRESS = '1'; |
|
| 59 | - const VERIFIED = '2'; |
|
| 60 | - |
|
| 61 | - /** @var IDBConnection database connection */ |
|
| 62 | - private $connection; |
|
| 63 | - |
|
| 64 | - /** @var string table name */ |
|
| 65 | - private $table = 'accounts'; |
|
| 66 | - |
|
| 67 | - /** @var EventDispatcherInterface */ |
|
| 68 | - private $eventDispatcher; |
|
| 69 | - |
|
| 70 | - /** @var IJobList */ |
|
| 71 | - private $jobList; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * AccountManager constructor. |
|
| 75 | - * |
|
| 76 | - * @param IDBConnection $connection |
|
| 77 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 78 | - * @param IJobList $jobList |
|
| 79 | - */ |
|
| 80 | - public function __construct(IDBConnection $connection, |
|
| 81 | - EventDispatcherInterface $eventDispatcher, |
|
| 82 | - IJobList $jobList) { |
|
| 83 | - $this->connection = $connection; |
|
| 84 | - $this->eventDispatcher = $eventDispatcher; |
|
| 85 | - $this->jobList = $jobList; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * update user record |
|
| 90 | - * |
|
| 91 | - * @param IUser $user |
|
| 92 | - * @param $data |
|
| 93 | - */ |
|
| 94 | - public function updateUser(IUser $user, $data) { |
|
| 95 | - $userData = $this->getUser($user); |
|
| 96 | - $updated = true; |
|
| 97 | - if (empty($userData)) { |
|
| 98 | - $this->insertNewUser($user, $data); |
|
| 99 | - } elseif ($userData !== $data) { |
|
| 100 | - $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 101 | - $data = $this->updateVerifyStatus($userData, $data); |
|
| 102 | - $this->updateExistingUser($user, $data); |
|
| 103 | - } else { |
|
| 104 | - // nothing needs to be done if new and old data set are the same |
|
| 105 | - $updated = false; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($updated) { |
|
| 109 | - $this->eventDispatcher->dispatch( |
|
| 110 | - 'OC\AccountManager::userUpdated', |
|
| 111 | - new GenericEvent($user, $data) |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * delete user from accounts table |
|
| 118 | - * |
|
| 119 | - * @param IUser $user |
|
| 120 | - */ |
|
| 121 | - public function deleteUser(IUser $user) { |
|
| 122 | - $uid = $user->getUID(); |
|
| 123 | - $query = $this->connection->getQueryBuilder(); |
|
| 124 | - $query->delete($this->table) |
|
| 125 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 126 | - ->execute(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * get stored data from a given user |
|
| 131 | - * |
|
| 132 | - * @param IUser $user |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function getUser(IUser $user) { |
|
| 136 | - $uid = $user->getUID(); |
|
| 137 | - $query = $this->connection->getQueryBuilder(); |
|
| 138 | - $query->select('data')->from($this->table) |
|
| 139 | - ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 140 | - ->setParameter('uid', $uid); |
|
| 141 | - $query->execute(); |
|
| 142 | - $result = $query->execute()->fetchAll(); |
|
| 143 | - |
|
| 144 | - if (empty($result)) { |
|
| 145 | - $userData = $this->buildDefaultUserRecord($user); |
|
| 146 | - $this->insertNewUser($user, $userData); |
|
| 147 | - return $userData; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $userDataArray = json_decode($result[0]['data'], true); |
|
| 151 | - |
|
| 152 | - $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 153 | - |
|
| 154 | - return $userDataArray; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 159 | - * |
|
| 160 | - * @param $oldData |
|
| 161 | - * @param $newData |
|
| 162 | - * @param IUser $user |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 166 | - if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 167 | - $this->jobList->add('OC\Settings\BackgroundJobs\VerifyUserData', |
|
| 168 | - [ |
|
| 169 | - 'verificationCode' => '', |
|
| 170 | - 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 171 | - 'type' => self::PROPERTY_EMAIL, |
|
| 172 | - 'uid' => $user->getUID(), |
|
| 173 | - 'try' => 0, |
|
| 174 | - 'lastRun' => time() |
|
| 175 | - ] |
|
| 176 | - ); |
|
| 177 | - $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $newData; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * make sure that all expected data are set |
|
| 185 | - * |
|
| 186 | - * @param array $userData |
|
| 187 | - * @return array |
|
| 188 | - */ |
|
| 189 | - protected function addMissingDefaultValues(array $userData) { |
|
| 190 | - |
|
| 191 | - foreach ($userData as $key => $value) { |
|
| 192 | - if (!isset($userData[$key]['verified'])) { |
|
| 193 | - $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $userData; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * reset verification status if personal data changed |
|
| 202 | - * |
|
| 203 | - * @param array $oldData |
|
| 204 | - * @param array $newData |
|
| 205 | - * @return array |
|
| 206 | - */ |
|
| 207 | - protected function updateVerifyStatus($oldData, $newData) { |
|
| 208 | - |
|
| 209 | - // which account was already verified successfully? |
|
| 210 | - $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 211 | - $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 212 | - $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 213 | - |
|
| 214 | - // keep old verification status if we don't have a new one |
|
| 215 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 216 | - // keep old verification status if value didn't changed and an old value exists |
|
| 217 | - $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 218 | - $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 222 | - // keep old verification status if value didn't changed and an old value exists |
|
| 223 | - $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 224 | - $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 228 | - // keep old verification status if value didn't changed and an old value exists |
|
| 229 | - $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 230 | - $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // reset verification status if a value from a previously verified data was changed |
|
| 234 | - if($twitterVerified && |
|
| 235 | - $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 236 | - ) { |
|
| 237 | - $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - if($websiteVerified && |
|
| 241 | - $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 242 | - ) { |
|
| 243 | - $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if($emailVerified && |
|
| 247 | - $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 248 | - ) { |
|
| 249 | - $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $newData; |
|
| 253 | - |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * add new user to accounts table |
|
| 258 | - * |
|
| 259 | - * @param IUser $user |
|
| 260 | - * @param array $data |
|
| 261 | - */ |
|
| 262 | - protected function insertNewUser(IUser $user, $data) { |
|
| 263 | - $uid = $user->getUID(); |
|
| 264 | - $jsonEncodedData = json_encode($data); |
|
| 265 | - $query = $this->connection->getQueryBuilder(); |
|
| 266 | - $query->insert($this->table) |
|
| 267 | - ->values( |
|
| 268 | - [ |
|
| 269 | - 'uid' => $query->createNamedParameter($uid), |
|
| 270 | - 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 271 | - ] |
|
| 272 | - ) |
|
| 273 | - ->execute(); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * update existing user in accounts table |
|
| 278 | - * |
|
| 279 | - * @param IUser $user |
|
| 280 | - * @param array $data |
|
| 281 | - */ |
|
| 282 | - protected function updateExistingUser(IUser $user, $data) { |
|
| 283 | - $uid = $user->getUID(); |
|
| 284 | - $jsonEncodedData = json_encode($data); |
|
| 285 | - $query = $this->connection->getQueryBuilder(); |
|
| 286 | - $query->update($this->table) |
|
| 287 | - ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 288 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 289 | - ->execute(); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * build default user record in case not data set exists yet |
|
| 294 | - * |
|
| 295 | - * @param IUser $user |
|
| 296 | - * @return array |
|
| 297 | - */ |
|
| 298 | - protected function buildDefaultUserRecord(IUser $user) { |
|
| 299 | - return [ |
|
| 300 | - self::PROPERTY_DISPLAYNAME => |
|
| 301 | - [ |
|
| 302 | - 'value' => $user->getDisplayName(), |
|
| 303 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 304 | - 'verified' => self::NOT_VERIFIED, |
|
| 305 | - ], |
|
| 306 | - self::PROPERTY_ADDRESS => |
|
| 307 | - [ |
|
| 308 | - 'value' => '', |
|
| 309 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 310 | - 'verified' => self::NOT_VERIFIED, |
|
| 311 | - ], |
|
| 312 | - self::PROPERTY_WEBSITE => |
|
| 313 | - [ |
|
| 314 | - 'value' => '', |
|
| 315 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 316 | - 'verified' => self::NOT_VERIFIED, |
|
| 317 | - ], |
|
| 318 | - self::PROPERTY_EMAIL => |
|
| 319 | - [ |
|
| 320 | - 'value' => $user->getEMailAddress(), |
|
| 321 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 322 | - 'verified' => self::NOT_VERIFIED, |
|
| 323 | - ], |
|
| 324 | - self::PROPERTY_AVATAR => |
|
| 325 | - [ |
|
| 326 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 327 | - ], |
|
| 328 | - self::PROPERTY_PHONE => |
|
| 329 | - [ |
|
| 330 | - 'value' => '', |
|
| 331 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 332 | - 'verified' => self::NOT_VERIFIED, |
|
| 333 | - ], |
|
| 334 | - self::PROPERTY_TWITTER => |
|
| 335 | - [ |
|
| 336 | - 'value' => '', |
|
| 337 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 338 | - 'verified' => self::NOT_VERIFIED, |
|
| 339 | - ], |
|
| 340 | - ]; |
|
| 341 | - } |
|
| 42 | + /** nobody can see my account details */ |
|
| 43 | + const VISIBILITY_PRIVATE = 'private'; |
|
| 44 | + /** only contacts, especially trusted servers can see my contact details */ |
|
| 45 | + const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 46 | + /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 47 | + const VISIBILITY_PUBLIC = 'public'; |
|
| 48 | + |
|
| 49 | + const PROPERTY_AVATAR = 'avatar'; |
|
| 50 | + const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 51 | + const PROPERTY_PHONE = 'phone'; |
|
| 52 | + const PROPERTY_EMAIL = 'email'; |
|
| 53 | + const PROPERTY_WEBSITE = 'website'; |
|
| 54 | + const PROPERTY_ADDRESS = 'address'; |
|
| 55 | + const PROPERTY_TWITTER = 'twitter'; |
|
| 56 | + |
|
| 57 | + const NOT_VERIFIED = '0'; |
|
| 58 | + const VERIFICATION_IN_PROGRESS = '1'; |
|
| 59 | + const VERIFIED = '2'; |
|
| 60 | + |
|
| 61 | + /** @var IDBConnection database connection */ |
|
| 62 | + private $connection; |
|
| 63 | + |
|
| 64 | + /** @var string table name */ |
|
| 65 | + private $table = 'accounts'; |
|
| 66 | + |
|
| 67 | + /** @var EventDispatcherInterface */ |
|
| 68 | + private $eventDispatcher; |
|
| 69 | + |
|
| 70 | + /** @var IJobList */ |
|
| 71 | + private $jobList; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * AccountManager constructor. |
|
| 75 | + * |
|
| 76 | + * @param IDBConnection $connection |
|
| 77 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 78 | + * @param IJobList $jobList |
|
| 79 | + */ |
|
| 80 | + public function __construct(IDBConnection $connection, |
|
| 81 | + EventDispatcherInterface $eventDispatcher, |
|
| 82 | + IJobList $jobList) { |
|
| 83 | + $this->connection = $connection; |
|
| 84 | + $this->eventDispatcher = $eventDispatcher; |
|
| 85 | + $this->jobList = $jobList; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * update user record |
|
| 90 | + * |
|
| 91 | + * @param IUser $user |
|
| 92 | + * @param $data |
|
| 93 | + */ |
|
| 94 | + public function updateUser(IUser $user, $data) { |
|
| 95 | + $userData = $this->getUser($user); |
|
| 96 | + $updated = true; |
|
| 97 | + if (empty($userData)) { |
|
| 98 | + $this->insertNewUser($user, $data); |
|
| 99 | + } elseif ($userData !== $data) { |
|
| 100 | + $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 101 | + $data = $this->updateVerifyStatus($userData, $data); |
|
| 102 | + $this->updateExistingUser($user, $data); |
|
| 103 | + } else { |
|
| 104 | + // nothing needs to be done if new and old data set are the same |
|
| 105 | + $updated = false; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($updated) { |
|
| 109 | + $this->eventDispatcher->dispatch( |
|
| 110 | + 'OC\AccountManager::userUpdated', |
|
| 111 | + new GenericEvent($user, $data) |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * delete user from accounts table |
|
| 118 | + * |
|
| 119 | + * @param IUser $user |
|
| 120 | + */ |
|
| 121 | + public function deleteUser(IUser $user) { |
|
| 122 | + $uid = $user->getUID(); |
|
| 123 | + $query = $this->connection->getQueryBuilder(); |
|
| 124 | + $query->delete($this->table) |
|
| 125 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 126 | + ->execute(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * get stored data from a given user |
|
| 131 | + * |
|
| 132 | + * @param IUser $user |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function getUser(IUser $user) { |
|
| 136 | + $uid = $user->getUID(); |
|
| 137 | + $query = $this->connection->getQueryBuilder(); |
|
| 138 | + $query->select('data')->from($this->table) |
|
| 139 | + ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 140 | + ->setParameter('uid', $uid); |
|
| 141 | + $query->execute(); |
|
| 142 | + $result = $query->execute()->fetchAll(); |
|
| 143 | + |
|
| 144 | + if (empty($result)) { |
|
| 145 | + $userData = $this->buildDefaultUserRecord($user); |
|
| 146 | + $this->insertNewUser($user, $userData); |
|
| 147 | + return $userData; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $userDataArray = json_decode($result[0]['data'], true); |
|
| 151 | + |
|
| 152 | + $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 153 | + |
|
| 154 | + return $userDataArray; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 159 | + * |
|
| 160 | + * @param $oldData |
|
| 161 | + * @param $newData |
|
| 162 | + * @param IUser $user |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 166 | + if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 167 | + $this->jobList->add('OC\Settings\BackgroundJobs\VerifyUserData', |
|
| 168 | + [ |
|
| 169 | + 'verificationCode' => '', |
|
| 170 | + 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 171 | + 'type' => self::PROPERTY_EMAIL, |
|
| 172 | + 'uid' => $user->getUID(), |
|
| 173 | + 'try' => 0, |
|
| 174 | + 'lastRun' => time() |
|
| 175 | + ] |
|
| 176 | + ); |
|
| 177 | + $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $newData; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * make sure that all expected data are set |
|
| 185 | + * |
|
| 186 | + * @param array $userData |
|
| 187 | + * @return array |
|
| 188 | + */ |
|
| 189 | + protected function addMissingDefaultValues(array $userData) { |
|
| 190 | + |
|
| 191 | + foreach ($userData as $key => $value) { |
|
| 192 | + if (!isset($userData[$key]['verified'])) { |
|
| 193 | + $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $userData; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * reset verification status if personal data changed |
|
| 202 | + * |
|
| 203 | + * @param array $oldData |
|
| 204 | + * @param array $newData |
|
| 205 | + * @return array |
|
| 206 | + */ |
|
| 207 | + protected function updateVerifyStatus($oldData, $newData) { |
|
| 208 | + |
|
| 209 | + // which account was already verified successfully? |
|
| 210 | + $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 211 | + $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 212 | + $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 213 | + |
|
| 214 | + // keep old verification status if we don't have a new one |
|
| 215 | + if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 216 | + // keep old verification status if value didn't changed and an old value exists |
|
| 217 | + $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 218 | + $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 222 | + // keep old verification status if value didn't changed and an old value exists |
|
| 223 | + $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 224 | + $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 228 | + // keep old verification status if value didn't changed and an old value exists |
|
| 229 | + $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 230 | + $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // reset verification status if a value from a previously verified data was changed |
|
| 234 | + if($twitterVerified && |
|
| 235 | + $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 236 | + ) { |
|
| 237 | + $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + if($websiteVerified && |
|
| 241 | + $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 242 | + ) { |
|
| 243 | + $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if($emailVerified && |
|
| 247 | + $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 248 | + ) { |
|
| 249 | + $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $newData; |
|
| 253 | + |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * add new user to accounts table |
|
| 258 | + * |
|
| 259 | + * @param IUser $user |
|
| 260 | + * @param array $data |
|
| 261 | + */ |
|
| 262 | + protected function insertNewUser(IUser $user, $data) { |
|
| 263 | + $uid = $user->getUID(); |
|
| 264 | + $jsonEncodedData = json_encode($data); |
|
| 265 | + $query = $this->connection->getQueryBuilder(); |
|
| 266 | + $query->insert($this->table) |
|
| 267 | + ->values( |
|
| 268 | + [ |
|
| 269 | + 'uid' => $query->createNamedParameter($uid), |
|
| 270 | + 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 271 | + ] |
|
| 272 | + ) |
|
| 273 | + ->execute(); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * update existing user in accounts table |
|
| 278 | + * |
|
| 279 | + * @param IUser $user |
|
| 280 | + * @param array $data |
|
| 281 | + */ |
|
| 282 | + protected function updateExistingUser(IUser $user, $data) { |
|
| 283 | + $uid = $user->getUID(); |
|
| 284 | + $jsonEncodedData = json_encode($data); |
|
| 285 | + $query = $this->connection->getQueryBuilder(); |
|
| 286 | + $query->update($this->table) |
|
| 287 | + ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 288 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 289 | + ->execute(); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * build default user record in case not data set exists yet |
|
| 294 | + * |
|
| 295 | + * @param IUser $user |
|
| 296 | + * @return array |
|
| 297 | + */ |
|
| 298 | + protected function buildDefaultUserRecord(IUser $user) { |
|
| 299 | + return [ |
|
| 300 | + self::PROPERTY_DISPLAYNAME => |
|
| 301 | + [ |
|
| 302 | + 'value' => $user->getDisplayName(), |
|
| 303 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 304 | + 'verified' => self::NOT_VERIFIED, |
|
| 305 | + ], |
|
| 306 | + self::PROPERTY_ADDRESS => |
|
| 307 | + [ |
|
| 308 | + 'value' => '', |
|
| 309 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 310 | + 'verified' => self::NOT_VERIFIED, |
|
| 311 | + ], |
|
| 312 | + self::PROPERTY_WEBSITE => |
|
| 313 | + [ |
|
| 314 | + 'value' => '', |
|
| 315 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 316 | + 'verified' => self::NOT_VERIFIED, |
|
| 317 | + ], |
|
| 318 | + self::PROPERTY_EMAIL => |
|
| 319 | + [ |
|
| 320 | + 'value' => $user->getEMailAddress(), |
|
| 321 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 322 | + 'verified' => self::NOT_VERIFIED, |
|
| 323 | + ], |
|
| 324 | + self::PROPERTY_AVATAR => |
|
| 325 | + [ |
|
| 326 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 327 | + ], |
|
| 328 | + self::PROPERTY_PHONE => |
|
| 329 | + [ |
|
| 330 | + 'value' => '', |
|
| 331 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 332 | + 'verified' => self::NOT_VERIFIED, |
|
| 333 | + ], |
|
| 334 | + self::PROPERTY_TWITTER => |
|
| 335 | + [ |
|
| 336 | + 'value' => '', |
|
| 337 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 338 | + 'verified' => self::NOT_VERIFIED, |
|
| 339 | + ], |
|
| 340 | + ]; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | 343 | } |
@@ -28,35 +28,35 @@ |
||
| 28 | 28 | use OCP\Util; |
| 29 | 29 | |
| 30 | 30 | class Application extends App { |
| 31 | - public function __construct () { |
|
| 32 | - parent::__construct('twofactor_backupcodes'); |
|
| 33 | - } |
|
| 31 | + public function __construct () { |
|
| 32 | + parent::__construct('twofactor_backupcodes'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Register the different app parts |
|
| 37 | - */ |
|
| 38 | - public function register() { |
|
| 39 | - $this->registerHooksAndEvents(); |
|
| 40 | - $this->registerPersonalPage(); |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * Register the different app parts |
|
| 37 | + */ |
|
| 38 | + public function register() { |
|
| 39 | + $this->registerHooksAndEvents(); |
|
| 40 | + $this->registerPersonalPage(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Register the hooks and events |
|
| 45 | - */ |
|
| 46 | - public function registerHooksAndEvents() { |
|
| 47 | - Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser'); |
|
| 48 | - } |
|
| 43 | + /** |
|
| 44 | + * Register the hooks and events |
|
| 45 | + */ |
|
| 46 | + public function registerHooksAndEvents() { |
|
| 47 | + Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser'); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function deleteUser($params) { |
|
| 51 | - /** @var BackupCodeMapper $mapper */ |
|
| 52 | - $mapper = $this->getContainer()->query(BackupCodeMapper::class); |
|
| 53 | - $mapper->deleteCodesByUserId($params['uid']); |
|
| 54 | - } |
|
| 50 | + public function deleteUser($params) { |
|
| 51 | + /** @var BackupCodeMapper $mapper */ |
|
| 52 | + $mapper = $this->getContainer()->query(BackupCodeMapper::class); |
|
| 53 | + $mapper->deleteCodesByUserId($params['uid']); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Register personal settings for notifications and emails |
|
| 58 | - */ |
|
| 59 | - public function registerPersonalPage() { |
|
| 60 | - \OCP\App::registerPersonal($this->getContainer()->getAppName(), 'settings/personal'); |
|
| 61 | - } |
|
| 56 | + /** |
|
| 57 | + * Register personal settings for notifications and emails |
|
| 58 | + */ |
|
| 59 | + public function registerPersonalPage() { |
|
| 60 | + \OCP\App::registerPersonal($this->getContainer()->getAppName(), 'settings/personal'); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | use OCP\Util; |
| 29 | 29 | |
| 30 | 30 | class Application extends App { |
| 31 | - public function __construct () { |
|
| 31 | + public function __construct() { |
|
| 32 | 32 | parent::__construct('twofactor_backupcodes'); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -27,48 +27,48 @@ |
||
| 27 | 27 | |
| 28 | 28 | class BackupCodeMapper extends Mapper { |
| 29 | 29 | |
| 30 | - public function __construct(IDBConnection $db) { |
|
| 31 | - parent::__construct($db, 'twofactor_backup_codes'); |
|
| 32 | - } |
|
| 30 | + public function __construct(IDBConnection $db) { |
|
| 31 | + parent::__construct($db, 'twofactor_backup_codes'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param IUser $user |
|
| 36 | - * @return BackupCode[] |
|
| 37 | - */ |
|
| 38 | - public function getBackupCodes(IUser $user) { |
|
| 39 | - /* @var IQueryBuilder $qb */ |
|
| 40 | - $qb = $this->db->getQueryBuilder(); |
|
| 34 | + /** |
|
| 35 | + * @param IUser $user |
|
| 36 | + * @return BackupCode[] |
|
| 37 | + */ |
|
| 38 | + public function getBackupCodes(IUser $user) { |
|
| 39 | + /* @var IQueryBuilder $qb */ |
|
| 40 | + $qb = $this->db->getQueryBuilder(); |
|
| 41 | 41 | |
| 42 | - $qb->select('id', 'user_id', 'code', 'used') |
|
| 43 | - ->from('twofactor_backup_codes') |
|
| 44 | - ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
| 45 | - $result = $qb->execute(); |
|
| 42 | + $qb->select('id', 'user_id', 'code', 'used') |
|
| 43 | + ->from('twofactor_backup_codes') |
|
| 44 | + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
| 45 | + $result = $qb->execute(); |
|
| 46 | 46 | |
| 47 | - $rows = $result->fetchAll(); |
|
| 48 | - $result->closeCursor(); |
|
| 47 | + $rows = $result->fetchAll(); |
|
| 48 | + $result->closeCursor(); |
|
| 49 | 49 | |
| 50 | - return array_map(function ($row) { |
|
| 51 | - return BackupCode::fromRow($row); |
|
| 52 | - }, $rows); |
|
| 53 | - } |
|
| 50 | + return array_map(function ($row) { |
|
| 51 | + return BackupCode::fromRow($row); |
|
| 52 | + }, $rows); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param IUser $user |
|
| 57 | - */ |
|
| 58 | - public function deleteCodes(IUser $user) { |
|
| 59 | - $this->deleteCodesByUserId($user->getUID()); |
|
| 60 | - } |
|
| 55 | + /** |
|
| 56 | + * @param IUser $user |
|
| 57 | + */ |
|
| 58 | + public function deleteCodes(IUser $user) { |
|
| 59 | + $this->deleteCodesByUserId($user->getUID()); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param string $uid |
|
| 64 | - */ |
|
| 65 | - public function deleteCodesByUserId($uid) { |
|
| 66 | - /* @var IQueryBuilder $qb */ |
|
| 67 | - $qb = $this->db->getQueryBuilder(); |
|
| 62 | + /** |
|
| 63 | + * @param string $uid |
|
| 64 | + */ |
|
| 65 | + public function deleteCodesByUserId($uid) { |
|
| 66 | + /* @var IQueryBuilder $qb */ |
|
| 67 | + $qb = $this->db->getQueryBuilder(); |
|
| 68 | 68 | |
| 69 | - $qb->delete('twofactor_backup_codes') |
|
| 70 | - ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($uid))); |
|
| 71 | - $qb->execute(); |
|
| 72 | - } |
|
| 69 | + $qb->delete('twofactor_backup_codes') |
|
| 70 | + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($uid))); |
|
| 71 | + $qb->execute(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | } |