2021-10-14 04:19:40 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-27 04:08:53 -04:00
|
|
|
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2021-10-14 04:19:40 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace OC\Core\Controller;
|
|
|
|
|
|
2021-11-04 21:42:44 -04:00
|
|
|
use OC\Profile\ProfileManager;
|
2021-10-14 04:19:40 -04:00
|
|
|
use OCP\AppFramework\Controller;
|
2024-06-12 05:46:12 -04:00
|
|
|
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
|
|
|
|
|
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
|
2024-01-10 06:35:44 -05:00
|
|
|
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
2024-07-25 07:24:59 -04:00
|
|
|
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
2024-01-18 04:38:37 -05:00
|
|
|
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
2024-07-25 07:24:59 -04:00
|
|
|
use OCP\AppFramework\Http\Attribute\PublicPage;
|
2024-06-12 05:46:12 -04:00
|
|
|
use OCP\AppFramework\Http\Attribute\UserRateLimit;
|
2021-10-14 04:19:40 -04:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
2022-09-12 16:58:53 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2023-10-26 13:30:22 -04:00
|
|
|
use OCP\INavigationManager;
|
2021-10-14 04:19:40 -04:00
|
|
|
use OCP\IRequest;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use OCP\IUserSession;
|
2022-09-12 16:58:53 -04:00
|
|
|
use OCP\Profile\BeforeTemplateRenderedEvent;
|
2021-11-04 21:42:44 -04:00
|
|
|
use OCP\Share\IManager as IShareManager;
|
2021-10-14 04:19:40 -04:00
|
|
|
use OCP\UserStatus\IManager as IUserStatusManager;
|
|
|
|
|
|
2024-01-18 04:38:37 -05:00
|
|
|
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
2021-10-14 04:19:40 -04:00
|
|
|
class ProfilePageController extends Controller {
|
2023-06-05 11:12:42 -04:00
|
|
|
public function __construct(
|
|
|
|
|
string $appName,
|
|
|
|
|
IRequest $request,
|
|
|
|
|
private IInitialState $initialStateService,
|
|
|
|
|
private ProfileManager $profileManager,
|
|
|
|
|
private IShareManager $shareManager,
|
|
|
|
|
private IUserManager $userManager,
|
|
|
|
|
private IUserSession $userSession,
|
|
|
|
|
private IUserStatusManager $userStatusManager,
|
2023-10-26 13:30:22 -04:00
|
|
|
private INavigationManager $navigationManager,
|
2023-06-05 11:12:42 -04:00
|
|
|
private IEventDispatcher $eventDispatcher,
|
|
|
|
|
) {
|
2021-10-14 04:19:40 -04:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 07:24:59 -04:00
|
|
|
#[PublicPage]
|
|
|
|
|
#[NoCSRFRequired]
|
2024-01-10 06:35:44 -05:00
|
|
|
#[FrontpageRoute(verb: 'GET', url: '/u/{targetUserId}')]
|
2024-06-12 05:46:12 -04:00
|
|
|
#[BruteForceProtection(action: 'user')]
|
|
|
|
|
#[UserRateLimit(limit: 30, period: 120)]
|
|
|
|
|
#[AnonRateLimit(limit: 30, period: 120)]
|
2021-10-14 04:19:40 -04:00
|
|
|
public function index(string $targetUserId): TemplateResponse {
|
2021-11-04 21:42:44 -04:00
|
|
|
$profileNotFoundTemplate = new TemplateResponse(
|
|
|
|
|
'core',
|
|
|
|
|
'404-profile',
|
|
|
|
|
[],
|
|
|
|
|
TemplateResponse::RENDER_AS_GUEST,
|
|
|
|
|
);
|
|
|
|
|
|
2021-11-05 05:44:51 -04:00
|
|
|
$targetUser = $this->userManager->get($targetUserId);
|
2024-06-12 05:46:12 -04:00
|
|
|
if ($targetUser === null) {
|
|
|
|
|
$profileNotFoundTemplate->throttle();
|
|
|
|
|
return $profileNotFoundTemplate;
|
|
|
|
|
}
|
|
|
|
|
if (!$targetUser->isEnabled()) {
|
2021-11-04 21:42:44 -04:00
|
|
|
return $profileNotFoundTemplate;
|
2021-10-14 04:19:40 -04:00
|
|
|
}
|
|
|
|
|
$visitingUser = $this->userSession->getUser();
|
|
|
|
|
|
2022-03-10 21:11:28 -05:00
|
|
|
if (!$this->profileManager->isProfileEnabled($targetUser)) {
|
2021-11-04 21:42:44 -04:00
|
|
|
return $profileNotFoundTemplate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run user enumeration checks only if viewing another user's profile
|
|
|
|
|
if ($targetUser !== $visitingUser) {
|
2021-11-05 05:44:51 -04:00
|
|
|
if (!$this->shareManager->currentUserCanEnumerateTargetUser($visitingUser, $targetUser)) {
|
2021-11-04 21:42:44 -04:00
|
|
|
return $profileNotFoundTemplate;
|
|
|
|
|
}
|
2021-10-14 04:19:40 -04:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 17:58:44 -05:00
|
|
|
if ($visitingUser !== null) {
|
|
|
|
|
$userStatuses = $this->userStatusManager->getUserStatuses([$targetUserId]);
|
|
|
|
|
$status = $userStatuses[$targetUserId] ?? null;
|
|
|
|
|
if ($status !== null) {
|
|
|
|
|
$this->initialStateService->provideInitialState('status', [
|
|
|
|
|
'icon' => $status->getIcon(),
|
|
|
|
|
'message' => $status->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2021-10-14 04:19:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'profileParameters',
|
2023-10-23 06:28:48 -04:00
|
|
|
$this->profileManager->getProfileFields($targetUser, $visitingUser),
|
2021-10-14 04:19:40 -04:00
|
|
|
);
|
|
|
|
|
|
2023-11-02 18:43:56 -04:00
|
|
|
if ($targetUser === $visitingUser) {
|
|
|
|
|
$this->navigationManager->setActiveEntry('profile');
|
|
|
|
|
}
|
2023-10-26 13:30:22 -04:00
|
|
|
|
2022-09-12 16:58:53 -04:00
|
|
|
$this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($targetUserId));
|
|
|
|
|
|
2021-12-01 18:08:08 -05:00
|
|
|
\OCP\Util::addScript('core', 'profile');
|
2021-10-14 04:19:40 -04:00
|
|
|
|
|
|
|
|
return new TemplateResponse(
|
|
|
|
|
'core',
|
|
|
|
|
'profile',
|
|
|
|
|
[],
|
|
|
|
|
$this->userSession->isLoggedIn() ? TemplateResponse::RENDER_AS_USER : TemplateResponse::RENDER_AS_PUBLIC,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|