Passed
Push — master ( 4908d8...fbbdc6 )
by Joas
16:12 queued 12s
created
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   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -61,353 +61,353 @@
 block discarded – undo
61 61
  *   logout()
62 62
  */
63 63
 class OC_User {
64
-	private static $_usedBackends = [];
65
-
66
-	private static $_setupedBackends = [];
67
-
68
-	// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
69
-	private static $incognitoMode = false;
70
-
71
-	/**
72
-	 * Adds the backend to the list of used backends
73
-	 *
74
-	 * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
75
-	 * @return bool
76
-	 *
77
-	 * Set the User Authentication Module
78
-	 * @suppress PhanDeprecatedFunction
79
-	 */
80
-	public static function useBackend($backend = 'database') {
81
-		if ($backend instanceof \OCP\UserInterface) {
82
-			self::$_usedBackends[get_class($backend)] = $backend;
83
-			\OC::$server->getUserManager()->registerBackend($backend);
84
-		} else {
85
-			// You'll never know what happens
86
-			if (null === $backend or !is_string($backend)) {
87
-				$backend = 'database';
88
-			}
89
-
90
-			// Load backend
91
-			switch ($backend) {
92
-				case 'database':
93
-				case 'mysql':
94
-				case 'sqlite':
95
-					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
96
-					self::$_usedBackends[$backend] = new \OC\User\Database();
97
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
98
-					break;
99
-				case 'dummy':
100
-					self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
101
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
102
-					break;
103
-				default:
104
-					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
105
-					$className = 'OC_USER_' . strtoupper($backend);
106
-					self::$_usedBackends[$backend] = new $className();
107
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
108
-					break;
109
-			}
110
-		}
111
-		return true;
112
-	}
113
-
114
-	/**
115
-	 * remove all used backends
116
-	 */
117
-	public static function clearBackends() {
118
-		self::$_usedBackends = [];
119
-		\OC::$server->getUserManager()->clearBackends();
120
-	}
121
-
122
-	/**
123
-	 * setup the configured backends in config.php
124
-	 * @suppress PhanDeprecatedFunction
125
-	 */
126
-	public static function setupBackends() {
127
-		OC_App::loadApps(['prelogin']);
128
-		$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
129
-		if (isset($backends['default']) && !$backends['default']) {
130
-			// clear default backends
131
-			self::clearBackends();
132
-		}
133
-		foreach ($backends as $i => $config) {
134
-			if (!is_array($config)) {
135
-				continue;
136
-			}
137
-			$class = $config['class'];
138
-			$arguments = $config['arguments'];
139
-			if (class_exists($class)) {
140
-				if (array_search($i, self::$_setupedBackends) === false) {
141
-					// make a reflection object
142
-					$reflectionObj = new ReflectionClass($class);
143
-
144
-					// use Reflection to create a new instance, using the $args
145
-					$backend = $reflectionObj->newInstanceArgs($arguments);
146
-					self::useBackend($backend);
147
-					self::$_setupedBackends[] = $i;
148
-				} else {
149
-					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
150
-				}
151
-			} else {
152
-				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
153
-			}
154
-		}
155
-	}
156
-
157
-	/**
158
-	 * Try to login a user, assuming authentication
159
-	 * has already happened (e.g. via Single Sign On).
160
-	 *
161
-	 * Log in a user and regenerate a new session.
162
-	 *
163
-	 * @param \OCP\Authentication\IApacheBackend $backend
164
-	 * @return bool
165
-	 */
166
-	public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
167
-		$uid = $backend->getCurrentUserId();
168
-		$run = true;
169
-		OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
170
-
171
-		if ($uid) {
172
-			if (self::getUser() !== $uid) {
173
-				self::setUserId($uid);
174
-				$userSession = \OC::$server->getUserSession();
175
-				if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
176
-					$message = \OC::$server->getL10N('lib')->t('User disabled');
177
-					throw new LoginException($message);
178
-				}
179
-				$userSession->setLoginName($uid);
180
-				$request = OC::$server->getRequest();
181
-				$password = null;
182
-				if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
183
-					$password = $backend->getCurrentUserSecret();
184
-				}
185
-				$userSession->createSessionToken($request, $uid, $uid, $password);
186
-				$userSession->createRememberMeToken($userSession->getUser());
187
-				// setup the filesystem
188
-				OC_Util::setupFS($uid);
189
-				// first call the post_login hooks, the login-process needs to be
190
-				// completed before we can safely create the users folder.
191
-				// For example encryption needs to initialize the users keys first
192
-				// before we can create the user folder with the skeleton files
193
-				OC_Hook::emit(
194
-					'OC_User',
195
-					'post_login',
196
-					[
197
-						'uid' => $uid,
198
-						'password' => $password,
199
-						'isTokenLogin' => false,
200
-					]
201
-				);
202
-				/** @var IEventDispatcher $dispatcher */
203
-				$dispatcher = \OC::$server->get(IEventDispatcher::class);
204
-				$dispatcher->dispatchTyped(new UserLoggedInEvent(
205
-					\OC::$server->get(IUserManager::class)->get($uid),
206
-					$uid,
207
-					null,
208
-					false)
209
-				);
210
-
211
-				//trigger creation of user home and /files folder
212
-				\OC::$server->getUserFolder($uid);
213
-			}
214
-			return true;
215
-		}
216
-		return false;
217
-	}
218
-
219
-	/**
220
-	 * Verify with Apache whether user is authenticated.
221
-	 *
222
-	 * @return boolean|null
223
-	 *          true: authenticated
224
-	 *          false: not authenticated
225
-	 *          null: not handled / no backend available
226
-	 */
227
-	public static function handleApacheAuth() {
228
-		$backend = self::findFirstActiveUsedBackend();
229
-		if ($backend) {
230
-			OC_App::loadApps();
231
-
232
-			//setup extra user backends
233
-			self::setupBackends();
234
-			\OC::$server->getUserSession()->unsetMagicInCookie();
235
-
236
-			return self::loginWithApache($backend);
237
-		}
238
-
239
-		return null;
240
-	}
241
-
242
-
243
-	/**
244
-	 * Sets user id for session and triggers emit
245
-	 *
246
-	 * @param string $uid
247
-	 */
248
-	public static function setUserId($uid) {
249
-		$userSession = \OC::$server->getUserSession();
250
-		$userManager = \OC::$server->getUserManager();
251
-		if ($user = $userManager->get($uid)) {
252
-			$userSession->setUser($user);
253
-		} else {
254
-			\OC::$server->getSession()->set('user_id', $uid);
255
-		}
256
-	}
257
-
258
-	/**
259
-	 * Check if the user is logged in, considers also the HTTP basic credentials
260
-	 *
261
-	 * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
262
-	 * @return bool
263
-	 */
264
-	public static function isLoggedIn() {
265
-		return \OC::$server->getUserSession()->isLoggedIn();
266
-	}
267
-
268
-	/**
269
-	 * set incognito mode, e.g. if a user wants to open a public link
270
-	 *
271
-	 * @param bool $status
272
-	 */
273
-	public static function setIncognitoMode($status) {
274
-		self::$incognitoMode = $status;
275
-	}
276
-
277
-	/**
278
-	 * get incognito mode status
279
-	 *
280
-	 * @return bool
281
-	 */
282
-	public static function isIncognitoMode() {
283
-		return self::$incognitoMode;
284
-	}
285
-
286
-	/**
287
-	 * Returns the current logout URL valid for the currently logged-in user
288
-	 *
289
-	 * @param \OCP\IURLGenerator $urlGenerator
290
-	 * @return string
291
-	 */
292
-	public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
293
-		$backend = self::findFirstActiveUsedBackend();
294
-		if ($backend) {
295
-			return $backend->getLogoutUrl();
296
-		}
297
-
298
-		$user = \OC::$server->getUserSession()->getUser();
299
-		if ($user instanceof \OCP\IUser) {
300
-			$backend = $user->getBackend();
301
-			if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
302
-				return $backend->getLogoutUrl();
303
-			}
304
-		}
305
-
306
-		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
307
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
308
-
309
-		return $logoutUrl;
310
-	}
311
-
312
-	/**
313
-	 * Check if the user is an admin user
314
-	 *
315
-	 * @param string $uid uid of the admin
316
-	 * @return bool
317
-	 */
318
-	public static function isAdminUser($uid) {
319
-		$group = \OC::$server->getGroupManager()->get('admin');
320
-		$user = \OC::$server->getUserManager()->get($uid);
321
-		if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
322
-			return true;
323
-		}
324
-		return false;
325
-	}
326
-
327
-
328
-	/**
329
-	 * get the user id of the user currently logged in.
330
-	 *
331
-	 * @return string|false uid or false
332
-	 */
333
-	public static function getUser() {
334
-		$uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
335
-		if (!is_null($uid) && self::$incognitoMode === false) {
336
-			return $uid;
337
-		} else {
338
-			return false;
339
-		}
340
-	}
341
-
342
-	/**
343
-	 * Set password
344
-	 *
345
-	 * @param string $uid The username
346
-	 * @param string $password The new password
347
-	 * @param string $recoveryPassword for the encryption app to reset encryption keys
348
-	 * @return bool
349
-	 *
350
-	 * Change the password of a user
351
-	 */
352
-	public static function setPassword($uid, $password, $recoveryPassword = null) {
353
-		$user = \OC::$server->getUserManager()->get($uid);
354
-		if ($user) {
355
-			return $user->setPassword($password, $recoveryPassword);
356
-		} else {
357
-			return false;
358
-		}
359
-	}
360
-
361
-	/**
362
-	 * @param string $uid The username
363
-	 * @return string
364
-	 *
365
-	 * returns the path to the users home directory
366
-	 * @deprecated Use \OC::$server->getUserManager->getHome()
367
-	 */
368
-	public static function getHome($uid) {
369
-		$user = \OC::$server->getUserManager()->get($uid);
370
-		if ($user) {
371
-			return $user->getHome();
372
-		} else {
373
-			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
374
-		}
375
-	}
376
-
377
-	/**
378
-	 * Get a list of all users display name
379
-	 *
380
-	 * @param string $search
381
-	 * @param int $limit
382
-	 * @param int $offset
383
-	 * @return array associative array with all display names (value) and corresponding uids (key)
384
-	 *
385
-	 * Get a list of all display names and user ids.
386
-	 * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
387
-	 */
388
-	public static function getDisplayNames($search = '', $limit = null, $offset = null) {
389
-		$displayNames = [];
390
-		$users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
391
-		foreach ($users as $user) {
392
-			$displayNames[$user->getUID()] = $user->getDisplayName();
393
-		}
394
-		return $displayNames;
395
-	}
396
-
397
-	/**
398
-	 * Returns the first active backend from self::$_usedBackends.
399
-	 *
400
-	 * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
401
-	 */
402
-	private static function findFirstActiveUsedBackend() {
403
-		foreach (self::$_usedBackends as $backend) {
404
-			if ($backend instanceof OCP\Authentication\IApacheBackend) {
405
-				if ($backend->isSessionActive()) {
406
-					return $backend;
407
-				}
408
-			}
409
-		}
410
-
411
-		return null;
412
-	}
64
+    private static $_usedBackends = [];
65
+
66
+    private static $_setupedBackends = [];
67
+
68
+    // bool, stores if a user want to access a resource anonymously, e.g if they open a public link
69
+    private static $incognitoMode = false;
70
+
71
+    /**
72
+     * Adds the backend to the list of used backends
73
+     *
74
+     * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
75
+     * @return bool
76
+     *
77
+     * Set the User Authentication Module
78
+     * @suppress PhanDeprecatedFunction
79
+     */
80
+    public static function useBackend($backend = 'database') {
81
+        if ($backend instanceof \OCP\UserInterface) {
82
+            self::$_usedBackends[get_class($backend)] = $backend;
83
+            \OC::$server->getUserManager()->registerBackend($backend);
84
+        } else {
85
+            // You'll never know what happens
86
+            if (null === $backend or !is_string($backend)) {
87
+                $backend = 'database';
88
+            }
89
+
90
+            // Load backend
91
+            switch ($backend) {
92
+                case 'database':
93
+                case 'mysql':
94
+                case 'sqlite':
95
+                    \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
96
+                    self::$_usedBackends[$backend] = new \OC\User\Database();
97
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
98
+                    break;
99
+                case 'dummy':
100
+                    self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
101
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
102
+                    break;
103
+                default:
104
+                    \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
105
+                    $className = 'OC_USER_' . strtoupper($backend);
106
+                    self::$_usedBackends[$backend] = new $className();
107
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
108
+                    break;
109
+            }
110
+        }
111
+        return true;
112
+    }
113
+
114
+    /**
115
+     * remove all used backends
116
+     */
117
+    public static function clearBackends() {
118
+        self::$_usedBackends = [];
119
+        \OC::$server->getUserManager()->clearBackends();
120
+    }
121
+
122
+    /**
123
+     * setup the configured backends in config.php
124
+     * @suppress PhanDeprecatedFunction
125
+     */
126
+    public static function setupBackends() {
127
+        OC_App::loadApps(['prelogin']);
128
+        $backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
129
+        if (isset($backends['default']) && !$backends['default']) {
130
+            // clear default backends
131
+            self::clearBackends();
132
+        }
133
+        foreach ($backends as $i => $config) {
134
+            if (!is_array($config)) {
135
+                continue;
136
+            }
137
+            $class = $config['class'];
138
+            $arguments = $config['arguments'];
139
+            if (class_exists($class)) {
140
+                if (array_search($i, self::$_setupedBackends) === false) {
141
+                    // make a reflection object
142
+                    $reflectionObj = new ReflectionClass($class);
143
+
144
+                    // use Reflection to create a new instance, using the $args
145
+                    $backend = $reflectionObj->newInstanceArgs($arguments);
146
+                    self::useBackend($backend);
147
+                    self::$_setupedBackends[] = $i;
148
+                } else {
149
+                    \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
150
+                }
151
+            } else {
152
+                \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
153
+            }
154
+        }
155
+    }
156
+
157
+    /**
158
+     * Try to login a user, assuming authentication
159
+     * has already happened (e.g. via Single Sign On).
160
+     *
161
+     * Log in a user and regenerate a new session.
162
+     *
163
+     * @param \OCP\Authentication\IApacheBackend $backend
164
+     * @return bool
165
+     */
166
+    public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
167
+        $uid = $backend->getCurrentUserId();
168
+        $run = true;
169
+        OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
170
+
171
+        if ($uid) {
172
+            if (self::getUser() !== $uid) {
173
+                self::setUserId($uid);
174
+                $userSession = \OC::$server->getUserSession();
175
+                if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
176
+                    $message = \OC::$server->getL10N('lib')->t('User disabled');
177
+                    throw new LoginException($message);
178
+                }
179
+                $userSession->setLoginName($uid);
180
+                $request = OC::$server->getRequest();
181
+                $password = null;
182
+                if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
183
+                    $password = $backend->getCurrentUserSecret();
184
+                }
185
+                $userSession->createSessionToken($request, $uid, $uid, $password);
186
+                $userSession->createRememberMeToken($userSession->getUser());
187
+                // setup the filesystem
188
+                OC_Util::setupFS($uid);
189
+                // first call the post_login hooks, the login-process needs to be
190
+                // completed before we can safely create the users folder.
191
+                // For example encryption needs to initialize the users keys first
192
+                // before we can create the user folder with the skeleton files
193
+                OC_Hook::emit(
194
+                    'OC_User',
195
+                    'post_login',
196
+                    [
197
+                        'uid' => $uid,
198
+                        'password' => $password,
199
+                        'isTokenLogin' => false,
200
+                    ]
201
+                );
202
+                /** @var IEventDispatcher $dispatcher */
203
+                $dispatcher = \OC::$server->get(IEventDispatcher::class);
204
+                $dispatcher->dispatchTyped(new UserLoggedInEvent(
205
+                    \OC::$server->get(IUserManager::class)->get($uid),
206
+                    $uid,
207
+                    null,
208
+                    false)
209
+                );
210
+
211
+                //trigger creation of user home and /files folder
212
+                \OC::$server->getUserFolder($uid);
213
+            }
214
+            return true;
215
+        }
216
+        return false;
217
+    }
218
+
219
+    /**
220
+     * Verify with Apache whether user is authenticated.
221
+     *
222
+     * @return boolean|null
223
+     *          true: authenticated
224
+     *          false: not authenticated
225
+     *          null: not handled / no backend available
226
+     */
227
+    public static function handleApacheAuth() {
228
+        $backend = self::findFirstActiveUsedBackend();
229
+        if ($backend) {
230
+            OC_App::loadApps();
231
+
232
+            //setup extra user backends
233
+            self::setupBackends();
234
+            \OC::$server->getUserSession()->unsetMagicInCookie();
235
+
236
+            return self::loginWithApache($backend);
237
+        }
238
+
239
+        return null;
240
+    }
241
+
242
+
243
+    /**
244
+     * Sets user id for session and triggers emit
245
+     *
246
+     * @param string $uid
247
+     */
248
+    public static function setUserId($uid) {
249
+        $userSession = \OC::$server->getUserSession();
250
+        $userManager = \OC::$server->getUserManager();
251
+        if ($user = $userManager->get($uid)) {
252
+            $userSession->setUser($user);
253
+        } else {
254
+            \OC::$server->getSession()->set('user_id', $uid);
255
+        }
256
+    }
257
+
258
+    /**
259
+     * Check if the user is logged in, considers also the HTTP basic credentials
260
+     *
261
+     * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
262
+     * @return bool
263
+     */
264
+    public static function isLoggedIn() {
265
+        return \OC::$server->getUserSession()->isLoggedIn();
266
+    }
267
+
268
+    /**
269
+     * set incognito mode, e.g. if a user wants to open a public link
270
+     *
271
+     * @param bool $status
272
+     */
273
+    public static function setIncognitoMode($status) {
274
+        self::$incognitoMode = $status;
275
+    }
276
+
277
+    /**
278
+     * get incognito mode status
279
+     *
280
+     * @return bool
281
+     */
282
+    public static function isIncognitoMode() {
283
+        return self::$incognitoMode;
284
+    }
285
+
286
+    /**
287
+     * Returns the current logout URL valid for the currently logged-in user
288
+     *
289
+     * @param \OCP\IURLGenerator $urlGenerator
290
+     * @return string
291
+     */
292
+    public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
293
+        $backend = self::findFirstActiveUsedBackend();
294
+        if ($backend) {
295
+            return $backend->getLogoutUrl();
296
+        }
297
+
298
+        $user = \OC::$server->getUserSession()->getUser();
299
+        if ($user instanceof \OCP\IUser) {
300
+            $backend = $user->getBackend();
301
+            if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
302
+                return $backend->getLogoutUrl();
303
+            }
304
+        }
305
+
306
+        $logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
307
+        $logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
308
+
309
+        return $logoutUrl;
310
+    }
311
+
312
+    /**
313
+     * Check if the user is an admin user
314
+     *
315
+     * @param string $uid uid of the admin
316
+     * @return bool
317
+     */
318
+    public static function isAdminUser($uid) {
319
+        $group = \OC::$server->getGroupManager()->get('admin');
320
+        $user = \OC::$server->getUserManager()->get($uid);
321
+        if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
322
+            return true;
323
+        }
324
+        return false;
325
+    }
326
+
327
+
328
+    /**
329
+     * get the user id of the user currently logged in.
330
+     *
331
+     * @return string|false uid or false
332
+     */
333
+    public static function getUser() {
334
+        $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
335
+        if (!is_null($uid) && self::$incognitoMode === false) {
336
+            return $uid;
337
+        } else {
338
+            return false;
339
+        }
340
+    }
341
+
342
+    /**
343
+     * Set password
344
+     *
345
+     * @param string $uid The username
346
+     * @param string $password The new password
347
+     * @param string $recoveryPassword for the encryption app to reset encryption keys
348
+     * @return bool
349
+     *
350
+     * Change the password of a user
351
+     */
352
+    public static function setPassword($uid, $password, $recoveryPassword = null) {
353
+        $user = \OC::$server->getUserManager()->get($uid);
354
+        if ($user) {
355
+            return $user->setPassword($password, $recoveryPassword);
356
+        } else {
357
+            return false;
358
+        }
359
+    }
360
+
361
+    /**
362
+     * @param string $uid The username
363
+     * @return string
364
+     *
365
+     * returns the path to the users home directory
366
+     * @deprecated Use \OC::$server->getUserManager->getHome()
367
+     */
368
+    public static function getHome($uid) {
369
+        $user = \OC::$server->getUserManager()->get($uid);
370
+        if ($user) {
371
+            return $user->getHome();
372
+        } else {
373
+            return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
374
+        }
375
+    }
376
+
377
+    /**
378
+     * Get a list of all users display name
379
+     *
380
+     * @param string $search
381
+     * @param int $limit
382
+     * @param int $offset
383
+     * @return array associative array with all display names (value) and corresponding uids (key)
384
+     *
385
+     * Get a list of all display names and user ids.
386
+     * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
387
+     */
388
+    public static function getDisplayNames($search = '', $limit = null, $offset = null) {
389
+        $displayNames = [];
390
+        $users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
391
+        foreach ($users as $user) {
392
+            $displayNames[$user->getUID()] = $user->getDisplayName();
393
+        }
394
+        return $displayNames;
395
+    }
396
+
397
+    /**
398
+     * Returns the first active backend from self::$_usedBackends.
399
+     *
400
+     * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
401
+     */
402
+    private static function findFirstActiveUsedBackend() {
403
+        foreach (self::$_usedBackends as $backend) {
404
+            if ($backend instanceof OCP\Authentication\IApacheBackend) {
405
+                if ($backend->isSessionActive()) {
406
+                    return $backend;
407
+                }
408
+            }
409
+        }
410
+
411
+        return null;
412
+    }
413 413
 }
Please login to merge, or discard this patch.
core/Controller/WebAuthnController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
 			'preLoginNameUsedAsUserName',
78 78
 			['uid' => &$uid]
79 79
 		);
80
-		$this->logger->debug('Got UID: ' . $uid);
80
+		$this->logger->debug('Got UID: '.$uid);
81 81
 
82 82
 		$publicKeyCredentialRequestOptions = $this->webAuthnManger->startAuthentication($uid, $this->request->getServerHost());
83 83
 		$this->session->set(self::WEBAUTHN_LOGIN, json_encode($publicKeyCredentialRequestOptions));
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -42,77 +42,77 @@
 block discarded – undo
42 42
 use Webauthn\PublicKeyCredentialRequestOptions;
43 43
 
44 44
 class WebAuthnController extends Controller {
45
-	private const WEBAUTHN_LOGIN = 'webauthn_login';
46
-	private const WEBAUTHN_LOGIN_UID = 'webauthn_login_uid';
47
-
48
-	private Manager $webAuthnManger;
49
-	private ISession $session;
50
-	private LoggerInterface $logger;
51
-	private WebAuthnChain $webAuthnChain;
52
-	private UrlGenerator $urlGenerator;
53
-
54
-	public function __construct($appName, IRequest $request, Manager $webAuthnManger, ISession $session, LoggerInterface $logger, WebAuthnChain $webAuthnChain, URLGenerator $urlGenerator) {
55
-		parent::__construct($appName, $request);
56
-
57
-		$this->webAuthnManger = $webAuthnManger;
58
-		$this->session = $session;
59
-		$this->logger = $logger;
60
-		$this->webAuthnChain = $webAuthnChain;
61
-		$this->urlGenerator = $urlGenerator;
62
-	}
63
-
64
-	/**
65
-	 * @NoAdminRequired
66
-	 * @PublicPage
67
-	 */
68
-	#[UseSession]
69
-	public function startAuthentication(string $loginName): JSONResponse {
70
-		$this->logger->debug('Starting WebAuthn login');
71
-
72
-		$this->logger->debug('Converting login name to UID');
73
-		$uid = $loginName;
74
-		Util::emitHook(
75
-			'\OCA\Files_Sharing\API\Server2Server',
76
-			'preLoginNameUsedAsUserName',
77
-			['uid' => &$uid]
78
-		);
79
-		$this->logger->debug('Got UID: ' . $uid);
80
-
81
-		$publicKeyCredentialRequestOptions = $this->webAuthnManger->startAuthentication($uid, $this->request->getServerHost());
82
-		$this->session->set(self::WEBAUTHN_LOGIN, json_encode($publicKeyCredentialRequestOptions));
83
-		$this->session->set(self::WEBAUTHN_LOGIN_UID, $uid);
84
-
85
-		return new JSONResponse($publicKeyCredentialRequestOptions);
86
-	}
87
-
88
-	/**
89
-	 * @NoAdminRequired
90
-	 * @PublicPage
91
-	 */
92
-	#[UseSession]
93
-	public function finishAuthentication(string $data): JSONResponse {
94
-		$this->logger->debug('Validating WebAuthn login');
95
-
96
-		if (!$this->session->exists(self::WEBAUTHN_LOGIN) || !$this->session->exists(self::WEBAUTHN_LOGIN_UID)) {
97
-			$this->logger->debug('Trying to finish WebAuthn login without session data');
98
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
99
-		}
100
-
101
-		// Obtain the publicKeyCredentialOptions from when we started the registration
102
-		$publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::createFromString($this->session->get(self::WEBAUTHN_LOGIN));
103
-		$uid = $this->session->get(self::WEBAUTHN_LOGIN_UID);
104
-		$this->webAuthnManger->finishAuthentication($publicKeyCredentialRequestOptions, $data, $uid);
105
-
106
-		//TODO: add other parameters
107
-		$loginData = new LoginData(
108
-			$this->request,
109
-			$uid,
110
-			''
111
-		);
112
-		$this->webAuthnChain->process($loginData);
113
-
114
-		return new JSONResponse([
115
-			'defaultRedirectUrl' => $this->urlGenerator->linkToDefaultPageUrl(),
116
-		]);
117
-	}
45
+    private const WEBAUTHN_LOGIN = 'webauthn_login';
46
+    private const WEBAUTHN_LOGIN_UID = 'webauthn_login_uid';
47
+
48
+    private Manager $webAuthnManger;
49
+    private ISession $session;
50
+    private LoggerInterface $logger;
51
+    private WebAuthnChain $webAuthnChain;
52
+    private UrlGenerator $urlGenerator;
53
+
54
+    public function __construct($appName, IRequest $request, Manager $webAuthnManger, ISession $session, LoggerInterface $logger, WebAuthnChain $webAuthnChain, URLGenerator $urlGenerator) {
55
+        parent::__construct($appName, $request);
56
+
57
+        $this->webAuthnManger = $webAuthnManger;
58
+        $this->session = $session;
59
+        $this->logger = $logger;
60
+        $this->webAuthnChain = $webAuthnChain;
61
+        $this->urlGenerator = $urlGenerator;
62
+    }
63
+
64
+    /**
65
+     * @NoAdminRequired
66
+     * @PublicPage
67
+     */
68
+    #[UseSession]
69
+    public function startAuthentication(string $loginName): JSONResponse {
70
+        $this->logger->debug('Starting WebAuthn login');
71
+
72
+        $this->logger->debug('Converting login name to UID');
73
+        $uid = $loginName;
74
+        Util::emitHook(
75
+            '\OCA\Files_Sharing\API\Server2Server',
76
+            'preLoginNameUsedAsUserName',
77
+            ['uid' => &$uid]
78
+        );
79
+        $this->logger->debug('Got UID: ' . $uid);
80
+
81
+        $publicKeyCredentialRequestOptions = $this->webAuthnManger->startAuthentication($uid, $this->request->getServerHost());
82
+        $this->session->set(self::WEBAUTHN_LOGIN, json_encode($publicKeyCredentialRequestOptions));
83
+        $this->session->set(self::WEBAUTHN_LOGIN_UID, $uid);
84
+
85
+        return new JSONResponse($publicKeyCredentialRequestOptions);
86
+    }
87
+
88
+    /**
89
+     * @NoAdminRequired
90
+     * @PublicPage
91
+     */
92
+    #[UseSession]
93
+    public function finishAuthentication(string $data): JSONResponse {
94
+        $this->logger->debug('Validating WebAuthn login');
95
+
96
+        if (!$this->session->exists(self::WEBAUTHN_LOGIN) || !$this->session->exists(self::WEBAUTHN_LOGIN_UID)) {
97
+            $this->logger->debug('Trying to finish WebAuthn login without session data');
98
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
99
+        }
100
+
101
+        // Obtain the publicKeyCredentialOptions from when we started the registration
102
+        $publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::createFromString($this->session->get(self::WEBAUTHN_LOGIN));
103
+        $uid = $this->session->get(self::WEBAUTHN_LOGIN_UID);
104
+        $this->webAuthnManger->finishAuthentication($publicKeyCredentialRequestOptions, $data, $uid);
105
+
106
+        //TODO: add other parameters
107
+        $loginData = new LoginData(
108
+            $this->request,
109
+            $uid,
110
+            ''
111
+        );
112
+        $this->webAuthnChain->process($loginData);
113
+
114
+        return new JSONResponse([
115
+            'defaultRedirectUrl' => $this->urlGenerator->linkToDefaultPageUrl(),
116
+        ]);
117
+    }
118 118
 }
Please login to merge, or discard this patch.