Passed
Push — master ( a1ed1d...263a69 )
by John
16:05 queued 13s
created
apps/contactsinteraction/composer/composer/ClassLoader.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -370,18 +370,18 @@  discard block
 block discarded – undo
370 370
     private function findFileWithExtension($class, $ext)
371 371
     {
372 372
         // PSR-4 lookup
373
-        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
373
+        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext;
374 374
 
375 375
         $first = $class[0];
376 376
         if (isset($this->prefixLengthsPsr4[$first])) {
377 377
             $subPath = $class;
378 378
             while (false !== $lastPos = strrpos($subPath, '\\')) {
379 379
                 $subPath = substr($subPath, 0, $lastPos);
380
-                $search = $subPath . '\\';
380
+                $search = $subPath.'\\';
381 381
                 if (isset($this->prefixDirsPsr4[$search])) {
382
-                    $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
382
+                    $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1);
383 383
                     foreach ($this->prefixDirsPsr4[$search] as $dir) {
384
-                        if (file_exists($file = $dir . $pathEnd)) {
384
+                        if (file_exists($file = $dir.$pathEnd)) {
385 385
                             return $file;
386 386
                         }
387 387
                     }
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 
392 392
         // PSR-4 fallback dirs
393 393
         foreach ($this->fallbackDirsPsr4 as $dir) {
394
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
394
+            if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) {
395 395
                 return $file;
396 396
             }
397 397
         }
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
                 . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
404 404
         } else {
405 405
             // PEAR-like class name
406
-            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
406
+            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext;
407 407
         }
408 408
 
409 409
         if (isset($this->prefixesPsr0[$first])) {
410 410
             foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
411 411
                 if (0 === strpos($class, $prefix)) {
412 412
                     foreach ($dirs as $dir) {
413
-                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
413
+                        if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) {
414 414
                             return $file;
415 415
                         }
416 416
                     }
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 
421 421
         // PSR-0 fallback dirs
422 422
         foreach ($this->fallbackDirsPsr0 as $dir) {
423
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
423
+            if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) {
424 424
                 return $file;
425 425
             }
426 426
         }
Please login to merge, or discard this patch.
apps/files_sharing/public.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,15 +28,15 @@
 block discarded – undo
28 28
 $route = isset($_GET['download']) ? 'files_sharing.sharecontroller.downloadShare' : 'files_sharing.sharecontroller.showShare';
29 29
 
30 30
 if ($token !== '') {
31
-	$protocol = \OC::$server->getRequest()->getHttpProtocol();
32
-	if ($protocol == 'HTTP/1.0') {
33
-		http_response_code(302);
34
-	} else {
35
-		http_response_code(307);
36
-	}
37
-	header('Location: ' . $urlGenerator->linkToRoute($route, ['token' => $token]));
31
+    $protocol = \OC::$server->getRequest()->getHttpProtocol();
32
+    if ($protocol == 'HTTP/1.0') {
33
+        http_response_code(302);
34
+    } else {
35
+        http_response_code(307);
36
+    }
37
+    header('Location: ' . $urlGenerator->linkToRoute($route, ['token' => $token]));
38 38
 } else {
39
-	http_response_code(404);
40
-	$tmpl = new OCP\Template('', '404', 'guest');
41
-	print_unescaped($tmpl->fetchPage());
39
+    http_response_code(404);
40
+    $tmpl = new OCP\Template('', '404', 'guest');
41
+    print_unescaped($tmpl->fetchPage());
42 42
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 	} else {
35 35
 		http_response_code(307);
36 36
 	}
37
-	header('Location: ' . $urlGenerator->linkToRoute($route, ['token' => $token]));
37
+	header('Location: '.$urlGenerator->linkToRoute($route, ['token' => $token]));
38 38
 } else {
39 39
 	http_response_code(404);
40 40
 	$tmpl = new OCP\Template('', '404', 'guest');
Please login to merge, or discard this patch.
lib/private/Files/Type/TemplateManager.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@
 block discarded – undo
29 29
  * @deprecated 18.0.0
30 30
  */
31 31
 class TemplateManager {
32
-	protected $templates = [];
32
+    protected $templates = [];
33 33
 
34
-	public function registerTemplate($mimetype, $path) {
35
-		$this->templates[$mimetype] = $path;
36
-	}
34
+    public function registerTemplate($mimetype, $path) {
35
+        $this->templates[$mimetype] = $path;
36
+    }
37 37
 
38
-	/**
39
-	 * get the path of the template for a mimetype
40
-	 *
41
-	 * @deprecated 18.0.0
42
-	 * @param string $mimetype
43
-	 * @return string|null
44
-	 */
45
-	public function getTemplatePath($mimetype) {
46
-		if (isset($this->templates[$mimetype])) {
47
-			return $this->templates[$mimetype];
48
-		} else {
49
-			return null;
50
-		}
51
-	}
38
+    /**
39
+     * get the path of the template for a mimetype
40
+     *
41
+     * @deprecated 18.0.0
42
+     * @param string $mimetype
43
+     * @return string|null
44
+     */
45
+    public function getTemplatePath($mimetype) {
46
+        if (isset($this->templates[$mimetype])) {
47
+            return $this->templates[$mimetype];
48
+        } else {
49
+            return null;
50
+        }
51
+    }
52 52
 
53
-	/**
54
-	 * get the template content for a mimetype
55
-	 *
56
-	 * @deprecated 18.0.0
57
-	 * @param string $mimetype
58
-	 * @return string
59
-	 */
60
-	public function getTemplate($mimetype) {
61
-		$path = $this->getTemplatePath($mimetype);
62
-		if ($path) {
63
-			return file_get_contents($path);
64
-		} else {
65
-			return '';
66
-		}
67
-	}
53
+    /**
54
+     * get the template content for a mimetype
55
+     *
56
+     * @deprecated 18.0.0
57
+     * @param string $mimetype
58
+     * @return string
59
+     */
60
+    public function getTemplate($mimetype) {
61
+        $path = $this->getTemplatePath($mimetype);
62
+        if ($path) {
63
+            return file_get_contents($path);
64
+        } else {
65
+            return '';
66
+        }
67
+    }
68 68
 }
Please login to merge, or discard this patch.
lib/private/Route/CachingRouter.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 	 */
52 52
 	public function generate($name, $parameters = [], $absolute = false) {
53 53
 		asort($parameters);
54
-		$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . (int)$absolute;
54
+		$key = $this->context->getHost().'#'.$this->context->getBaseUrl().$name.sha1(json_encode($parameters)).(int) $absolute;
55 55
 		$cachedKey = $this->cache->get($key);
56 56
 		if ($cachedKey) {
57 57
 			return $cachedKey;
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -33,40 +33,40 @@
 block discarded – undo
33 33
 use Psr\Log\LoggerInterface;
34 34
 
35 35
 class CachingRouter extends Router {
36
-	protected ICache $cache;
36
+    protected ICache $cache;
37 37
 
38
-	public function __construct(
39
-		ICacheFactory $cacheFactory,
40
-		LoggerInterface $logger,
41
-		IRequest $request,
42
-		IConfig $config,
43
-		IEventLogger $eventLogger,
44
-		ContainerInterface $container
45
-	) {
46
-		$this->cache = $cacheFactory->createLocal('route');
47
-		parent::__construct($logger, $request, $config, $eventLogger, $container);
48
-	}
38
+    public function __construct(
39
+        ICacheFactory $cacheFactory,
40
+        LoggerInterface $logger,
41
+        IRequest $request,
42
+        IConfig $config,
43
+        IEventLogger $eventLogger,
44
+        ContainerInterface $container
45
+    ) {
46
+        $this->cache = $cacheFactory->createLocal('route');
47
+        parent::__construct($logger, $request, $config, $eventLogger, $container);
48
+    }
49 49
 
50
-	/**
51
-	 * Generate url based on $name and $parameters
52
-	 *
53
-	 * @param string $name Name of the route to use.
54
-	 * @param array $parameters Parameters for the route
55
-	 * @param bool $absolute
56
-	 * @return string
57
-	 */
58
-	public function generate($name, $parameters = [], $absolute = false) {
59
-		asort($parameters);
60
-		$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . (int)$absolute;
61
-		$cachedKey = $this->cache->get($key);
62
-		if ($cachedKey) {
63
-			return $cachedKey;
64
-		} else {
65
-			$url = parent::generate($name, $parameters, $absolute);
66
-			if ($url) {
67
-				$this->cache->set($key, $url, 3600);
68
-			}
69
-			return $url;
70
-		}
71
-	}
50
+    /**
51
+     * Generate url based on $name and $parameters
52
+     *
53
+     * @param string $name Name of the route to use.
54
+     * @param array $parameters Parameters for the route
55
+     * @param bool $absolute
56
+     * @return string
57
+     */
58
+    public function generate($name, $parameters = [], $absolute = false) {
59
+        asort($parameters);
60
+        $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . (int)$absolute;
61
+        $cachedKey = $this->cache->get($key);
62
+        if ($cachedKey) {
63
+            return $cachedKey;
64
+        } else {
65
+            $url = parent::generate($name, $parameters, $absolute);
66
+            if ($url) {
67
+                $this->cache->set($key, $url, 3600);
68
+            }
69
+            return $url;
70
+        }
71
+    }
72 72
 }
Please login to merge, or discard this patch.
apps/settings/lib/Settings/Personal/Security/WebAuthn.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -33,48 +33,48 @@
 block discarded – undo
33 33
 
34 34
 class WebAuthn implements ISettings {
35 35
 
36
-	/** @var PublicKeyCredentialMapper */
37
-	private $mapper;
36
+    /** @var PublicKeyCredentialMapper */
37
+    private $mapper;
38 38
 
39
-	/** @var string */
40
-	private $uid;
39
+    /** @var string */
40
+    private $uid;
41 41
 
42
-	/** @var IInitialStateService */
43
-	private $initialStateService;
42
+    /** @var IInitialStateService */
43
+    private $initialStateService;
44 44
 
45
-	/** @var Manager */
46
-	private $manager;
45
+    /** @var Manager */
46
+    private $manager;
47 47
 
48
-	public function __construct(PublicKeyCredentialMapper $mapper,
49
-								string $UserId,
50
-								IInitialStateService $initialStateService,
51
-								Manager $manager) {
52
-		$this->mapper = $mapper;
53
-		$this->uid = $UserId;
54
-		$this->initialStateService = $initialStateService;
55
-		$this->manager = $manager;
56
-	}
48
+    public function __construct(PublicKeyCredentialMapper $mapper,
49
+                                string $UserId,
50
+                                IInitialStateService $initialStateService,
51
+                                Manager $manager) {
52
+        $this->mapper = $mapper;
53
+        $this->uid = $UserId;
54
+        $this->initialStateService = $initialStateService;
55
+        $this->manager = $manager;
56
+    }
57 57
 
58
-	public function getForm() {
59
-		$this->initialStateService->provideInitialState(
60
-			Application::APP_ID,
61
-			'webauthn-devices',
62
-			$this->mapper->findAllForUid($this->uid)
63
-		);
58
+    public function getForm() {
59
+        $this->initialStateService->provideInitialState(
60
+            Application::APP_ID,
61
+            'webauthn-devices',
62
+            $this->mapper->findAllForUid($this->uid)
63
+        );
64 64
 
65
-		return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
66
-		]);
67
-	}
65
+        return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
66
+        ]);
67
+    }
68 68
 
69
-	public function getSection(): ?string {
70
-		if (!$this->manager->isWebAuthnAvailable()) {
71
-			return null;
72
-		}
69
+    public function getSection(): ?string {
70
+        if (!$this->manager->isWebAuthnAvailable()) {
71
+            return null;
72
+        }
73 73
 
74
-		return 'security';
75
-	}
74
+        return 'security';
75
+    }
76 76
 
77
-	public function getPriority(): int {
78
-		return 20;
79
-	}
77
+    public function getPriority(): int {
78
+        return 20;
79
+    }
80 80
 }
Please login to merge, or discard this patch.
lib/private/Authentication/WebAuthn/CredentialRepository.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
 		$uid = $publicKeyCredentialUserEntity->getId();
57 57
 		$entities = $this->credentialMapper->findAllForUid($uid);
58 58
 
59
-		return array_map(function (PublicKeyCredentialEntity $entity) {
59
+		return array_map(function(PublicKeyCredentialEntity $entity) {
60 60
 			return $entity->toPublicKeyCredentialSource();
61 61
 		}, $entities);
62 62
 	}
Please login to merge, or discard this patch.
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -33,61 +33,61 @@
 block discarded – undo
33 33
 use Webauthn\PublicKeyCredentialUserEntity;
34 34
 
35 35
 class CredentialRepository implements PublicKeyCredentialSourceRepository {
36
-	/** @var PublicKeyCredentialMapper */
37
-	private $credentialMapper;
36
+    /** @var PublicKeyCredentialMapper */
37
+    private $credentialMapper;
38 38
 
39
-	public function __construct(PublicKeyCredentialMapper $credentialMapper) {
40
-		$this->credentialMapper = $credentialMapper;
41
-	}
39
+    public function __construct(PublicKeyCredentialMapper $credentialMapper) {
40
+        $this->credentialMapper = $credentialMapper;
41
+    }
42 42
 
43
-	public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource {
44
-		try {
45
-			$entity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialId);
46
-			return $entity->toPublicKeyCredentialSource();
47
-		} catch (IMapperException $e) {
48
-			return  null;
49
-		}
50
-	}
43
+    public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource {
44
+        try {
45
+            $entity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialId);
46
+            return $entity->toPublicKeyCredentialSource();
47
+        } catch (IMapperException $e) {
48
+            return  null;
49
+        }
50
+    }
51 51
 
52
-	/**
53
-	 * @return PublicKeyCredentialSource[]
54
-	 */
55
-	public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity): array {
56
-		$uid = $publicKeyCredentialUserEntity->getId();
57
-		$entities = $this->credentialMapper->findAllForUid($uid);
52
+    /**
53
+     * @return PublicKeyCredentialSource[]
54
+     */
55
+    public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity): array {
56
+        $uid = $publicKeyCredentialUserEntity->getId();
57
+        $entities = $this->credentialMapper->findAllForUid($uid);
58 58
 
59
-		return array_map(function (PublicKeyCredentialEntity $entity) {
60
-			return $entity->toPublicKeyCredentialSource();
61
-		}, $entities);
62
-	}
59
+        return array_map(function (PublicKeyCredentialEntity $entity) {
60
+            return $entity->toPublicKeyCredentialSource();
61
+        }, $entities);
62
+    }
63 63
 
64
-	public function saveAndReturnCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): PublicKeyCredentialEntity {
65
-		$oldEntity = null;
64
+    public function saveAndReturnCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): PublicKeyCredentialEntity {
65
+        $oldEntity = null;
66 66
 
67
-		try {
68
-			$oldEntity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialSource->getPublicKeyCredentialId());
69
-		} catch (IMapperException $e) {
70
-		}
67
+        try {
68
+            $oldEntity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialSource->getPublicKeyCredentialId());
69
+        } catch (IMapperException $e) {
70
+        }
71 71
 
72
-		$defaultName = false;
73
-		if ($name === null) {
74
-			$defaultName = true;
75
-			$name = 'default';
76
-		}
72
+        $defaultName = false;
73
+        if ($name === null) {
74
+            $defaultName = true;
75
+            $name = 'default';
76
+        }
77 77
 
78
-		$entity = PublicKeyCredentialEntity::fromPublicKeyCrendentialSource($name, $publicKeyCredentialSource);
78
+        $entity = PublicKeyCredentialEntity::fromPublicKeyCrendentialSource($name, $publicKeyCredentialSource);
79 79
 
80
-		if ($oldEntity) {
81
-			$entity->setId($oldEntity->getId());
82
-			if ($defaultName) {
83
-				$entity->setName($oldEntity->getName());
84
-			}
85
-		}
80
+        if ($oldEntity) {
81
+            $entity->setId($oldEntity->getId());
82
+            if ($defaultName) {
83
+                $entity->setName($oldEntity->getName());
84
+            }
85
+        }
86 86
 
87
-		return $this->credentialMapper->insertOrUpdate($entity);
88
-	}
87
+        return $this->credentialMapper->insertOrUpdate($entity);
88
+    }
89 89
 
90
-	public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): void {
91
-		$this->saveAndReturnCredentialSource($publicKeyCredentialSource, $name);
92
-	}
90
+    public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): void {
91
+        $this->saveAndReturnCredentialSource($publicKeyCredentialSource, $name);
92
+    }
93 93
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Login/WebAuthnChain.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -25,72 +25,72 @@
 block discarded – undo
25 25
 namespace OC\Authentication\Login;
26 26
 
27 27
 class WebAuthnChain {
28
-	/** @var UserDisabledCheckCommand */
29
-	private $userDisabledCheckCommand;
28
+    /** @var UserDisabledCheckCommand */
29
+    private $userDisabledCheckCommand;
30 30
 
31
-	/** @var LoggedInCheckCommand */
32
-	private $loggedInCheckCommand;
31
+    /** @var LoggedInCheckCommand */
32
+    private $loggedInCheckCommand;
33 33
 
34
-	/** @var CompleteLoginCommand */
35
-	private $completeLoginCommand;
34
+    /** @var CompleteLoginCommand */
35
+    private $completeLoginCommand;
36 36
 
37
-	/** @var CreateSessionTokenCommand */
38
-	private $createSessionTokenCommand;
37
+    /** @var CreateSessionTokenCommand */
38
+    private $createSessionTokenCommand;
39 39
 
40
-	/** @var ClearLostPasswordTokensCommand */
41
-	private $clearLostPasswordTokensCommand;
40
+    /** @var ClearLostPasswordTokensCommand */
41
+    private $clearLostPasswordTokensCommand;
42 42
 
43
-	/** @var UpdateLastPasswordConfirmCommand */
44
-	private $updateLastPasswordConfirmCommand;
43
+    /** @var UpdateLastPasswordConfirmCommand */
44
+    private $updateLastPasswordConfirmCommand;
45 45
 
46
-	/** @var SetUserTimezoneCommand */
47
-	private $setUserTimezoneCommand;
46
+    /** @var SetUserTimezoneCommand */
47
+    private $setUserTimezoneCommand;
48 48
 
49
-	/** @var TwoFactorCommand */
50
-	private $twoFactorCommand;
49
+    /** @var TwoFactorCommand */
50
+    private $twoFactorCommand;
51 51
 
52
-	/** @var FinishRememberedLoginCommand */
53
-	private $finishRememberedLoginCommand;
52
+    /** @var FinishRememberedLoginCommand */
53
+    private $finishRememberedLoginCommand;
54 54
 
55
-	/** @var WebAuthnLoginCommand */
56
-	private $webAuthnLoginCommand;
55
+    /** @var WebAuthnLoginCommand */
56
+    private $webAuthnLoginCommand;
57 57
 
58
-	public function __construct(UserDisabledCheckCommand $userDisabledCheckCommand,
59
-								WebAuthnLoginCommand $webAuthnLoginCommand,
60
-								LoggedInCheckCommand $loggedInCheckCommand,
61
-								CompleteLoginCommand $completeLoginCommand,
62
-								CreateSessionTokenCommand $createSessionTokenCommand,
63
-								ClearLostPasswordTokensCommand $clearLostPasswordTokensCommand,
64
-								UpdateLastPasswordConfirmCommand $updateLastPasswordConfirmCommand,
65
-								SetUserTimezoneCommand $setUserTimezoneCommand,
66
-								TwoFactorCommand $twoFactorCommand,
67
-								FinishRememberedLoginCommand $finishRememberedLoginCommand
68
-	) {
69
-		$this->userDisabledCheckCommand = $userDisabledCheckCommand;
70
-		$this->webAuthnLoginCommand = $webAuthnLoginCommand;
71
-		$this->loggedInCheckCommand = $loggedInCheckCommand;
72
-		$this->completeLoginCommand = $completeLoginCommand;
73
-		$this->createSessionTokenCommand = $createSessionTokenCommand;
74
-		$this->clearLostPasswordTokensCommand = $clearLostPasswordTokensCommand;
75
-		$this->updateLastPasswordConfirmCommand = $updateLastPasswordConfirmCommand;
76
-		$this->setUserTimezoneCommand = $setUserTimezoneCommand;
77
-		$this->twoFactorCommand = $twoFactorCommand;
78
-		$this->finishRememberedLoginCommand = $finishRememberedLoginCommand;
79
-	}
58
+    public function __construct(UserDisabledCheckCommand $userDisabledCheckCommand,
59
+                                WebAuthnLoginCommand $webAuthnLoginCommand,
60
+                                LoggedInCheckCommand $loggedInCheckCommand,
61
+                                CompleteLoginCommand $completeLoginCommand,
62
+                                CreateSessionTokenCommand $createSessionTokenCommand,
63
+                                ClearLostPasswordTokensCommand $clearLostPasswordTokensCommand,
64
+                                UpdateLastPasswordConfirmCommand $updateLastPasswordConfirmCommand,
65
+                                SetUserTimezoneCommand $setUserTimezoneCommand,
66
+                                TwoFactorCommand $twoFactorCommand,
67
+                                FinishRememberedLoginCommand $finishRememberedLoginCommand
68
+    ) {
69
+        $this->userDisabledCheckCommand = $userDisabledCheckCommand;
70
+        $this->webAuthnLoginCommand = $webAuthnLoginCommand;
71
+        $this->loggedInCheckCommand = $loggedInCheckCommand;
72
+        $this->completeLoginCommand = $completeLoginCommand;
73
+        $this->createSessionTokenCommand = $createSessionTokenCommand;
74
+        $this->clearLostPasswordTokensCommand = $clearLostPasswordTokensCommand;
75
+        $this->updateLastPasswordConfirmCommand = $updateLastPasswordConfirmCommand;
76
+        $this->setUserTimezoneCommand = $setUserTimezoneCommand;
77
+        $this->twoFactorCommand = $twoFactorCommand;
78
+        $this->finishRememberedLoginCommand = $finishRememberedLoginCommand;
79
+    }
80 80
 
81
-	public function process(LoginData $loginData): LoginResult {
82
-		$chain = $this->userDisabledCheckCommand;
83
-		$chain
84
-			->setNext($this->webAuthnLoginCommand)
85
-			->setNext($this->loggedInCheckCommand)
86
-			->setNext($this->completeLoginCommand)
87
-			->setNext($this->createSessionTokenCommand)
88
-			->setNext($this->clearLostPasswordTokensCommand)
89
-			->setNext($this->updateLastPasswordConfirmCommand)
90
-			->setNext($this->setUserTimezoneCommand)
91
-			->setNext($this->twoFactorCommand)
92
-			->setNext($this->finishRememberedLoginCommand);
81
+    public function process(LoginData $loginData): LoginResult {
82
+        $chain = $this->userDisabledCheckCommand;
83
+        $chain
84
+            ->setNext($this->webAuthnLoginCommand)
85
+            ->setNext($this->loggedInCheckCommand)
86
+            ->setNext($this->completeLoginCommand)
87
+            ->setNext($this->createSessionTokenCommand)
88
+            ->setNext($this->clearLostPasswordTokensCommand)
89
+            ->setNext($this->updateLastPasswordConfirmCommand)
90
+            ->setNext($this->setUserTimezoneCommand)
91
+            ->setNext($this->twoFactorCommand)
92
+            ->setNext($this->finishRememberedLoginCommand);
93 93
 
94
-		return $chain->process($loginData);
95
-	}
94
+        return $chain->process($loginData);
95
+    }
96 96
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/Integration/IAddressBookProvider.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,43 +31,43 @@
 block discarded – undo
31 31
  */
32 32
 interface IAddressBookProvider {
33 33
 
34
-	/**
35
-	 * Provides the appId of the plugin
36
-	 *
37
-	 * @since 19.0.0
38
-	 * @return string AppId
39
-	 */
40
-	public function getAppId(): string;
34
+    /**
35
+     * Provides the appId of the plugin
36
+     *
37
+     * @since 19.0.0
38
+     * @return string AppId
39
+     */
40
+    public function getAppId(): string;
41 41
 
42
-	/**
43
-	 * Fetches all address books for a given principal uri
44
-	 *
45
-	 * @since 19.0.0
46
-	 * @param string $principalUri E.g. principals/users/user1
47
-	 * @return ExternalAddressBook[] Array of all address books
48
-	 */
49
-	public function fetchAllForAddressBookHome(string $principalUri): array;
42
+    /**
43
+     * Fetches all address books for a given principal uri
44
+     *
45
+     * @since 19.0.0
46
+     * @param string $principalUri E.g. principals/users/user1
47
+     * @return ExternalAddressBook[] Array of all address books
48
+     */
49
+    public function fetchAllForAddressBookHome(string $principalUri): array;
50 50
 
51
-	/**
52
-	 * Checks whether plugin has an address book for a given principalUri and URI
53
-	 *
54
-	 * @since 19.0.0
55
-	 * @param string $principalUri E.g. principals/users/user1
56
-	 * @param string $uri E.g. personal
57
-	 * @return bool True if address book for principalUri and URI exists, false otherwise
58
-	 */
59
-	public function hasAddressBookInAddressBookHome(string $principalUri, string $uri): bool;
51
+    /**
52
+     * Checks whether plugin has an address book for a given principalUri and URI
53
+     *
54
+     * @since 19.0.0
55
+     * @param string $principalUri E.g. principals/users/user1
56
+     * @param string $uri E.g. personal
57
+     * @return bool True if address book for principalUri and URI exists, false otherwise
58
+     */
59
+    public function hasAddressBookInAddressBookHome(string $principalUri, string $uri): bool;
60 60
 
61
-	/**
62
-	 * Fetches an address book for a given principalUri and URI
63
-	 * Returns null if address book does not exist
64
-	 *
65
-	 * @param string $principalUri E.g. principals/users/user1
66
-	 * @param string $uri E.g. personal
67
-	 *
68
-	 * @return ExternalAddressBook|null address book if it exists, null otherwise
69
-	 *@since 19.0.0
70
-	 */
71
-	public function getAddressBookInAddressBookHome(string $principalUri, string $uri): ?ExternalAddressBook;
61
+    /**
62
+     * Fetches an address book for a given principalUri and URI
63
+     * Returns null if address book does not exist
64
+     *
65
+     * @param string $principalUri E.g. principals/users/user1
66
+     * @param string $uri E.g. personal
67
+     *
68
+     * @return ExternalAddressBook|null address book if it exists, null otherwise
69
+     *@since 19.0.0
70
+     */
71
+    public function getAddressBookInAddressBookHome(string $principalUri, string $uri): ?ExternalAddressBook;
72 72
 
73 73
 }
Please login to merge, or discard this patch.
lib/private/legacy/OC_User.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 				case 'database':
92 92
 				case 'mysql':
93 93
 				case 'sqlite':
94
-					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
94
+					\OCP\Util::writeLog('core', 'Adding user backend '.$backend.'.', ILogger::DEBUG);
95 95
 					self::$_usedBackends[$backend] = new \OC\User\Database();
96 96
 					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
97 97
 					break;
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
101 101
 					break;
102 102
 				default:
103
-					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
104
-					$className = 'OC_USER_' . strtoupper($backend);
103
+					\OCP\Util::writeLog('core', 'Adding default user backend '.$backend.'.', ILogger::DEBUG);
104
+					$className = 'OC_USER_'.strtoupper($backend);
105 105
 					self::$_usedBackends[$backend] = new $className();
106 106
 					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
107 107
 					break;
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 					self::useBackend($backend);
146 146
 					self::$_setupedBackends[] = $i;
147 147
 				} else {
148
-					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
148
+					\OCP\Util::writeLog('core', 'User backend '.$class.' already initialized.', ILogger::DEBUG);
149 149
 				}
150 150
 			} else {
151
-				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
151
+				\OCP\Util::writeLog('core', 'User backend '.$class.' not found.', ILogger::ERROR);
152 152
 			}
153 153
 		}
154 154
 	}
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 		}
271 271
 
272 272
 		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
273
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
273
+		$logoutUrl .= '?requesttoken='.urlencode(\OCP\Util::callRegister());
274 274
 
275 275
 		return $logoutUrl;
276 276
 	}
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		if ($user) {
363 363
 			return $user->getHome();
364 364
 		} else {
365
-			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
365
+			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$uid;
366 366
 		}
367 367
 	}
368 368
 
Please login to merge, or discard this patch.
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -62,359 +62,359 @@
 block discarded – undo
62 62
  *   logout()
63 63
  */
64 64
 class OC_User {
65
-	private static $_usedBackends = [];
66
-
67
-	private static $_setupedBackends = [];
68
-
69
-	// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
70
-	private static $incognitoMode = false;
71
-
72
-	/**
73
-	 * Adds the backend to the list of used backends
74
-	 *
75
-	 * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
76
-	 * @return bool
77
-	 *
78
-	 * Set the User Authentication Module
79
-	 * @suppress PhanDeprecatedFunction
80
-	 */
81
-	public static function useBackend($backend = 'database') {
82
-		if ($backend instanceof \OCP\UserInterface) {
83
-			self::$_usedBackends[get_class($backend)] = $backend;
84
-			\OC::$server->getUserManager()->registerBackend($backend);
85
-		} else {
86
-			// You'll never know what happens
87
-			if (null === $backend or !is_string($backend)) {
88
-				$backend = 'database';
89
-			}
90
-
91
-			// Load backend
92
-			switch ($backend) {
93
-				case 'database':
94
-				case 'mysql':
95
-				case 'sqlite':
96
-					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
97
-					self::$_usedBackends[$backend] = new \OC\User\Database();
98
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
99
-					break;
100
-				case 'dummy':
101
-					self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
102
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
103
-					break;
104
-				default:
105
-					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
106
-					$className = 'OC_USER_' . strtoupper($backend);
107
-					self::$_usedBackends[$backend] = new $className();
108
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
109
-					break;
110
-			}
111
-		}
112
-		return true;
113
-	}
114
-
115
-	/**
116
-	 * remove all used backends
117
-	 */
118
-	public static function clearBackends() {
119
-		self::$_usedBackends = [];
120
-		\OC::$server->getUserManager()->clearBackends();
121
-	}
122
-
123
-	/**
124
-	 * setup the configured backends in config.php
125
-	 * @suppress PhanDeprecatedFunction
126
-	 */
127
-	public static function setupBackends() {
128
-		OC_App::loadApps(['prelogin']);
129
-		$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
130
-		if (isset($backends['default']) && !$backends['default']) {
131
-			// clear default backends
132
-			self::clearBackends();
133
-		}
134
-		foreach ($backends as $i => $config) {
135
-			if (!is_array($config)) {
136
-				continue;
137
-			}
138
-			$class = $config['class'];
139
-			$arguments = $config['arguments'];
140
-			if (class_exists($class)) {
141
-				if (array_search($i, self::$_setupedBackends) === false) {
142
-					// make a reflection object
143
-					$reflectionObj = new ReflectionClass($class);
144
-
145
-					// use Reflection to create a new instance, using the $args
146
-					$backend = $reflectionObj->newInstanceArgs($arguments);
147
-					self::useBackend($backend);
148
-					self::$_setupedBackends[] = $i;
149
-				} else {
150
-					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
151
-				}
152
-			} else {
153
-				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
154
-			}
155
-		}
156
-	}
157
-
158
-	/**
159
-	 * Try to login a user, assuming authentication
160
-	 * has already happened (e.g. via Single Sign On).
161
-	 *
162
-	 * Log in a user and regenerate a new session.
163
-	 *
164
-	 * @param \OCP\Authentication\IApacheBackend $backend
165
-	 * @return bool
166
-	 */
167
-	public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
168
-		$uid = $backend->getCurrentUserId();
169
-		$run = true;
170
-		OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
171
-
172
-		if ($uid) {
173
-			if (self::getUser() !== $uid) {
174
-				self::setUserId($uid);
175
-				$userSession = \OC::$server->getUserSession();
176
-
177
-				/** @var IEventDispatcher $dispatcher */
178
-				$dispatcher = \OC::$server->get(IEventDispatcher::class);
179
-
180
-				if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
181
-					$message = \OC::$server->getL10N('lib')->t('User disabled');
182
-					throw new LoginException($message);
183
-				}
184
-				$userSession->setLoginName($uid);
185
-				$request = OC::$server->getRequest();
186
-				$password = null;
187
-				if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
188
-					$password = $backend->getCurrentUserSecret();
189
-				}
190
-
191
-				/** @var IEventDispatcher $dispatcher */
192
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));
193
-
194
-				$userSession->createSessionToken($request, $uid, $uid, $password);
195
-				$userSession->createRememberMeToken($userSession->getUser());
196
-				// setup the filesystem
197
-				OC_Util::setupFS($uid);
198
-				// first call the post_login hooks, the login-process needs to be
199
-				// completed before we can safely create the users folder.
200
-				// For example encryption needs to initialize the users keys first
201
-				// before we can create the user folder with the skeleton files
202
-				OC_Hook::emit(
203
-					'OC_User',
204
-					'post_login',
205
-					[
206
-						'uid' => $uid,
207
-						'password' => $password,
208
-						'isTokenLogin' => false,
209
-					]
210
-				);
211
-				$dispatcher->dispatchTyped(new UserLoggedInEvent(
212
-					\OC::$server->get(IUserManager::class)->get($uid),
213
-					$uid,
214
-					null,
215
-					false)
216
-				);
217
-
218
-				//trigger creation of user home and /files folder
219
-				\OC::$server->getUserFolder($uid);
220
-			}
221
-			return true;
222
-		}
223
-		return false;
224
-	}
225
-
226
-	/**
227
-	 * Verify with Apache whether user is authenticated.
228
-	 *
229
-	 * @return boolean|null
230
-	 *          true: authenticated
231
-	 *          false: not authenticated
232
-	 *          null: not handled / no backend available
233
-	 */
234
-	public static function handleApacheAuth() {
235
-		$backend = self::findFirstActiveUsedBackend();
236
-		if ($backend) {
237
-			OC_App::loadApps();
238
-
239
-			//setup extra user backends
240
-			self::setupBackends();
241
-			\OC::$server->getUserSession()->unsetMagicInCookie();
242
-
243
-			return self::loginWithApache($backend);
244
-		}
245
-
246
-		return null;
247
-	}
248
-
249
-
250
-	/**
251
-	 * Sets user id for session and triggers emit
252
-	 *
253
-	 * @param string $uid
254
-	 */
255
-	public static function setUserId($uid) {
256
-		$userSession = \OC::$server->getUserSession();
257
-		$userManager = \OC::$server->getUserManager();
258
-		if ($user = $userManager->get($uid)) {
259
-			$userSession->setUser($user);
260
-		} else {
261
-			\OC::$server->getSession()->set('user_id', $uid);
262
-		}
263
-	}
264
-
265
-	/**
266
-	 * Check if the user is logged in, considers also the HTTP basic credentials
267
-	 *
268
-	 * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
269
-	 * @return bool
270
-	 */
271
-	public static function isLoggedIn() {
272
-		return \OC::$server->getUserSession()->isLoggedIn();
273
-	}
274
-
275
-	/**
276
-	 * set incognito mode, e.g. if a user wants to open a public link
277
-	 *
278
-	 * @param bool $status
279
-	 */
280
-	public static function setIncognitoMode($status) {
281
-		self::$incognitoMode = $status;
282
-	}
283
-
284
-	/**
285
-	 * get incognito mode status
286
-	 *
287
-	 * @return bool
288
-	 */
289
-	public static function isIncognitoMode() {
290
-		return self::$incognitoMode;
291
-	}
292
-
293
-	/**
294
-	 * Returns the current logout URL valid for the currently logged-in user
295
-	 *
296
-	 * @param \OCP\IURLGenerator $urlGenerator
297
-	 * @return string
298
-	 */
299
-	public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
300
-		$backend = self::findFirstActiveUsedBackend();
301
-		if ($backend) {
302
-			return $backend->getLogoutUrl();
303
-		}
304
-
305
-		$user = \OC::$server->getUserSession()->getUser();
306
-		if ($user instanceof \OCP\IUser) {
307
-			$backend = $user->getBackend();
308
-			if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
309
-				return $backend->getLogoutUrl();
310
-			}
311
-		}
312
-
313
-		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
314
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
315
-
316
-		return $logoutUrl;
317
-	}
318
-
319
-	/**
320
-	 * Check if the user is an admin user
321
-	 *
322
-	 * @param string $uid uid of the admin
323
-	 * @return bool
324
-	 */
325
-	public static function isAdminUser($uid) {
326
-		$group = \OC::$server->getGroupManager()->get('admin');
327
-		$user = \OC::$server->getUserManager()->get($uid);
328
-		if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
329
-			return true;
330
-		}
331
-		return false;
332
-	}
333
-
334
-
335
-	/**
336
-	 * get the user id of the user currently logged in.
337
-	 *
338
-	 * @return string|false uid or false
339
-	 */
340
-	public static function getUser() {
341
-		$uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
342
-		if (!is_null($uid) && self::$incognitoMode === false) {
343
-			return $uid;
344
-		} else {
345
-			return false;
346
-		}
347
-	}
348
-
349
-	/**
350
-	 * Set password
351
-	 *
352
-	 * @param string $uid The username
353
-	 * @param string $password The new password
354
-	 * @param string $recoveryPassword for the encryption app to reset encryption keys
355
-	 * @return bool
356
-	 *
357
-	 * Change the password of a user
358
-	 */
359
-	public static function setPassword($uid, $password, $recoveryPassword = null) {
360
-		$user = \OC::$server->getUserManager()->get($uid);
361
-		if ($user) {
362
-			return $user->setPassword($password, $recoveryPassword);
363
-		} else {
364
-			return false;
365
-		}
366
-	}
367
-
368
-	/**
369
-	 * @param string $uid The username
370
-	 * @return string
371
-	 *
372
-	 * returns the path to the users home directory
373
-	 * @deprecated Use \OC::$server->getUserManager->getHome()
374
-	 */
375
-	public static function getHome($uid) {
376
-		$user = \OC::$server->getUserManager()->get($uid);
377
-		if ($user) {
378
-			return $user->getHome();
379
-		} else {
380
-			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
381
-		}
382
-	}
383
-
384
-	/**
385
-	 * Get a list of all users display name
386
-	 *
387
-	 * @param string $search
388
-	 * @param int $limit
389
-	 * @param int $offset
390
-	 * @return array associative array with all display names (value) and corresponding uids (key)
391
-	 *
392
-	 * Get a list of all display names and user ids.
393
-	 * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
394
-	 */
395
-	public static function getDisplayNames($search = '', $limit = null, $offset = null) {
396
-		$displayNames = [];
397
-		$users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
398
-		foreach ($users as $user) {
399
-			$displayNames[$user->getUID()] = $user->getDisplayName();
400
-		}
401
-		return $displayNames;
402
-	}
403
-
404
-	/**
405
-	 * Returns the first active backend from self::$_usedBackends.
406
-	 *
407
-	 * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
408
-	 */
409
-	private static function findFirstActiveUsedBackend() {
410
-		foreach (self::$_usedBackends as $backend) {
411
-			if ($backend instanceof OCP\Authentication\IApacheBackend) {
412
-				if ($backend->isSessionActive()) {
413
-					return $backend;
414
-				}
415
-			}
416
-		}
417
-
418
-		return null;
419
-	}
65
+    private static $_usedBackends = [];
66
+
67
+    private static $_setupedBackends = [];
68
+
69
+    // bool, stores if a user want to access a resource anonymously, e.g if they open a public link
70
+    private static $incognitoMode = false;
71
+
72
+    /**
73
+     * Adds the backend to the list of used backends
74
+     *
75
+     * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
76
+     * @return bool
77
+     *
78
+     * Set the User Authentication Module
79
+     * @suppress PhanDeprecatedFunction
80
+     */
81
+    public static function useBackend($backend = 'database') {
82
+        if ($backend instanceof \OCP\UserInterface) {
83
+            self::$_usedBackends[get_class($backend)] = $backend;
84
+            \OC::$server->getUserManager()->registerBackend($backend);
85
+        } else {
86
+            // You'll never know what happens
87
+            if (null === $backend or !is_string($backend)) {
88
+                $backend = 'database';
89
+            }
90
+
91
+            // Load backend
92
+            switch ($backend) {
93
+                case 'database':
94
+                case 'mysql':
95
+                case 'sqlite':
96
+                    \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
97
+                    self::$_usedBackends[$backend] = new \OC\User\Database();
98
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
99
+                    break;
100
+                case 'dummy':
101
+                    self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
102
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
103
+                    break;
104
+                default:
105
+                    \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
106
+                    $className = 'OC_USER_' . strtoupper($backend);
107
+                    self::$_usedBackends[$backend] = new $className();
108
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
109
+                    break;
110
+            }
111
+        }
112
+        return true;
113
+    }
114
+
115
+    /**
116
+     * remove all used backends
117
+     */
118
+    public static function clearBackends() {
119
+        self::$_usedBackends = [];
120
+        \OC::$server->getUserManager()->clearBackends();
121
+    }
122
+
123
+    /**
124
+     * setup the configured backends in config.php
125
+     * @suppress PhanDeprecatedFunction
126
+     */
127
+    public static function setupBackends() {
128
+        OC_App::loadApps(['prelogin']);
129
+        $backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
130
+        if (isset($backends['default']) && !$backends['default']) {
131
+            // clear default backends
132
+            self::clearBackends();
133
+        }
134
+        foreach ($backends as $i => $config) {
135
+            if (!is_array($config)) {
136
+                continue;
137
+            }
138
+            $class = $config['class'];
139
+            $arguments = $config['arguments'];
140
+            if (class_exists($class)) {
141
+                if (array_search($i, self::$_setupedBackends) === false) {
142
+                    // make a reflection object
143
+                    $reflectionObj = new ReflectionClass($class);
144
+
145
+                    // use Reflection to create a new instance, using the $args
146
+                    $backend = $reflectionObj->newInstanceArgs($arguments);
147
+                    self::useBackend($backend);
148
+                    self::$_setupedBackends[] = $i;
149
+                } else {
150
+                    \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
151
+                }
152
+            } else {
153
+                \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
154
+            }
155
+        }
156
+    }
157
+
158
+    /**
159
+     * Try to login a user, assuming authentication
160
+     * has already happened (e.g. via Single Sign On).
161
+     *
162
+     * Log in a user and regenerate a new session.
163
+     *
164
+     * @param \OCP\Authentication\IApacheBackend $backend
165
+     * @return bool
166
+     */
167
+    public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
168
+        $uid = $backend->getCurrentUserId();
169
+        $run = true;
170
+        OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
171
+
172
+        if ($uid) {
173
+            if (self::getUser() !== $uid) {
174
+                self::setUserId($uid);
175
+                $userSession = \OC::$server->getUserSession();
176
+
177
+                /** @var IEventDispatcher $dispatcher */
178
+                $dispatcher = \OC::$server->get(IEventDispatcher::class);
179
+
180
+                if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
181
+                    $message = \OC::$server->getL10N('lib')->t('User disabled');
182
+                    throw new LoginException($message);
183
+                }
184
+                $userSession->setLoginName($uid);
185
+                $request = OC::$server->getRequest();
186
+                $password = null;
187
+                if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
188
+                    $password = $backend->getCurrentUserSecret();
189
+                }
190
+
191
+                /** @var IEventDispatcher $dispatcher */
192
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));
193
+
194
+                $userSession->createSessionToken($request, $uid, $uid, $password);
195
+                $userSession->createRememberMeToken($userSession->getUser());
196
+                // setup the filesystem
197
+                OC_Util::setupFS($uid);
198
+                // first call the post_login hooks, the login-process needs to be
199
+                // completed before we can safely create the users folder.
200
+                // For example encryption needs to initialize the users keys first
201
+                // before we can create the user folder with the skeleton files
202
+                OC_Hook::emit(
203
+                    'OC_User',
204
+                    'post_login',
205
+                    [
206
+                        'uid' => $uid,
207
+                        'password' => $password,
208
+                        'isTokenLogin' => false,
209
+                    ]
210
+                );
211
+                $dispatcher->dispatchTyped(new UserLoggedInEvent(
212
+                    \OC::$server->get(IUserManager::class)->get($uid),
213
+                    $uid,
214
+                    null,
215
+                    false)
216
+                );
217
+
218
+                //trigger creation of user home and /files folder
219
+                \OC::$server->getUserFolder($uid);
220
+            }
221
+            return true;
222
+        }
223
+        return false;
224
+    }
225
+
226
+    /**
227
+     * Verify with Apache whether user is authenticated.
228
+     *
229
+     * @return boolean|null
230
+     *          true: authenticated
231
+     *          false: not authenticated
232
+     *          null: not handled / no backend available
233
+     */
234
+    public static function handleApacheAuth() {
235
+        $backend = self::findFirstActiveUsedBackend();
236
+        if ($backend) {
237
+            OC_App::loadApps();
238
+
239
+            //setup extra user backends
240
+            self::setupBackends();
241
+            \OC::$server->getUserSession()->unsetMagicInCookie();
242
+
243
+            return self::loginWithApache($backend);
244
+        }
245
+
246
+        return null;
247
+    }
248
+
249
+
250
+    /**
251
+     * Sets user id for session and triggers emit
252
+     *
253
+     * @param string $uid
254
+     */
255
+    public static function setUserId($uid) {
256
+        $userSession = \OC::$server->getUserSession();
257
+        $userManager = \OC::$server->getUserManager();
258
+        if ($user = $userManager->get($uid)) {
259
+            $userSession->setUser($user);
260
+        } else {
261
+            \OC::$server->getSession()->set('user_id', $uid);
262
+        }
263
+    }
264
+
265
+    /**
266
+     * Check if the user is logged in, considers also the HTTP basic credentials
267
+     *
268
+     * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
269
+     * @return bool
270
+     */
271
+    public static function isLoggedIn() {
272
+        return \OC::$server->getUserSession()->isLoggedIn();
273
+    }
274
+
275
+    /**
276
+     * set incognito mode, e.g. if a user wants to open a public link
277
+     *
278
+     * @param bool $status
279
+     */
280
+    public static function setIncognitoMode($status) {
281
+        self::$incognitoMode = $status;
282
+    }
283
+
284
+    /**
285
+     * get incognito mode status
286
+     *
287
+     * @return bool
288
+     */
289
+    public static function isIncognitoMode() {
290
+        return self::$incognitoMode;
291
+    }
292
+
293
+    /**
294
+     * Returns the current logout URL valid for the currently logged-in user
295
+     *
296
+     * @param \OCP\IURLGenerator $urlGenerator
297
+     * @return string
298
+     */
299
+    public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
300
+        $backend = self::findFirstActiveUsedBackend();
301
+        if ($backend) {
302
+            return $backend->getLogoutUrl();
303
+        }
304
+
305
+        $user = \OC::$server->getUserSession()->getUser();
306
+        if ($user instanceof \OCP\IUser) {
307
+            $backend = $user->getBackend();
308
+            if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
309
+                return $backend->getLogoutUrl();
310
+            }
311
+        }
312
+
313
+        $logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
314
+        $logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
315
+
316
+        return $logoutUrl;
317
+    }
318
+
319
+    /**
320
+     * Check if the user is an admin user
321
+     *
322
+     * @param string $uid uid of the admin
323
+     * @return bool
324
+     */
325
+    public static function isAdminUser($uid) {
326
+        $group = \OC::$server->getGroupManager()->get('admin');
327
+        $user = \OC::$server->getUserManager()->get($uid);
328
+        if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
329
+            return true;
330
+        }
331
+        return false;
332
+    }
333
+
334
+
335
+    /**
336
+     * get the user id of the user currently logged in.
337
+     *
338
+     * @return string|false uid or false
339
+     */
340
+    public static function getUser() {
341
+        $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
342
+        if (!is_null($uid) && self::$incognitoMode === false) {
343
+            return $uid;
344
+        } else {
345
+            return false;
346
+        }
347
+    }
348
+
349
+    /**
350
+     * Set password
351
+     *
352
+     * @param string $uid The username
353
+     * @param string $password The new password
354
+     * @param string $recoveryPassword for the encryption app to reset encryption keys
355
+     * @return bool
356
+     *
357
+     * Change the password of a user
358
+     */
359
+    public static function setPassword($uid, $password, $recoveryPassword = null) {
360
+        $user = \OC::$server->getUserManager()->get($uid);
361
+        if ($user) {
362
+            return $user->setPassword($password, $recoveryPassword);
363
+        } else {
364
+            return false;
365
+        }
366
+    }
367
+
368
+    /**
369
+     * @param string $uid The username
370
+     * @return string
371
+     *
372
+     * returns the path to the users home directory
373
+     * @deprecated Use \OC::$server->getUserManager->getHome()
374
+     */
375
+    public static function getHome($uid) {
376
+        $user = \OC::$server->getUserManager()->get($uid);
377
+        if ($user) {
378
+            return $user->getHome();
379
+        } else {
380
+            return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
381
+        }
382
+    }
383
+
384
+    /**
385
+     * Get a list of all users display name
386
+     *
387
+     * @param string $search
388
+     * @param int $limit
389
+     * @param int $offset
390
+     * @return array associative array with all display names (value) and corresponding uids (key)
391
+     *
392
+     * Get a list of all display names and user ids.
393
+     * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
394
+     */
395
+    public static function getDisplayNames($search = '', $limit = null, $offset = null) {
396
+        $displayNames = [];
397
+        $users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
398
+        foreach ($users as $user) {
399
+            $displayNames[$user->getUID()] = $user->getDisplayName();
400
+        }
401
+        return $displayNames;
402
+    }
403
+
404
+    /**
405
+     * Returns the first active backend from self::$_usedBackends.
406
+     *
407
+     * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
408
+     */
409
+    private static function findFirstActiveUsedBackend() {
410
+        foreach (self::$_usedBackends as $backend) {
411
+            if ($backend instanceof OCP\Authentication\IApacheBackend) {
412
+                if ($backend->isSessionActive()) {
413
+                    return $backend;
414
+                }
415
+            }
416
+        }
417
+
418
+        return null;
419
+    }
420 420
 }
Please login to merge, or discard this patch.