Files
FOSSBilling/src/modules/Client/Controller/Client.php
T
Adam Daley a9b903c222 Codebase modernisation, configuration cleanup, and improved type safety (#2957)
* Refactor tests to replace depreciated functions

* Update Rector config and dependencies

* Rector: Add explicit string casting for stricter type safety

* Rector: Add return type hints to methods across codebase

* Rector: Increase dead code level and refactor invoice item logic

* Remove unnecessary `willReturn` from test mocks

Eliminate redundant `willReturn(null)` and similar calls from PHPUnit mock setups in legacy module tests, leaving only method expectations. Also update some test values to use floats for consistency.

* Refactor API controller and email adapter return values

* Update formatting and guidelines in `AGENTS.md`
2025-10-11 23:39:44 +01:00

86 lines
2.6 KiB
PHP

<?php
/**
* Copyright 2022-2025 FOSSBilling
* Copyright 2011-2021 BoxBilling, Inc.
* SPDX-License-Identifier: Apache-2.0.
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
*/
namespace Box\Mod\Client\Controller;
class Client implements \FOSSBilling\InjectionAwareInterface
{
protected ?\Pimple\Container $di = null;
public function setDi(\Pimple\Container $di): void
{
$this->di = $di;
}
public function getDi(): ?\Pimple\Container
{
return $this->di;
}
public function register(\Box_App &$app): void
{
$app->get('/client/reset-password-confirm/:hash', 'get_reset_password_confirm', ['hash' => '[a-z0-9]+'], static::class);
$app->get('/client', 'get_client_index', [], static::class);
$app->get('/client/logout', 'get_client_logout', [], static::class);
$app->get('/client/:page', 'get_client_page', ['page' => '[a-z0-9-]+'], static::class);
$app->get('/client/confirm-email/:hash', 'get_client_confirmation', ['page' => '[a-z0-9-]+'], static::class);
}
public function get_client_index(\Box_App $app): string
{
$this->di['is_client_logged'];
return $app->render('mod_client_index');
}
public function get_client_confirmation(\Box_App $app, $hash): never
{
$service = $this->di['mod_service']('client');
$service->approveClientEmailByHash($hash);
$systemService = $this->di['mod_service']('System');
$systemService->setPendingMessage(__trans('Email address was confirmed'));
$app->redirect('/');
}
public function get_client_logout(\Box_App $app): never
{
$api = $this->di['api_client'];
$api->profile_logout();
$app->redirect('/');
}
public function get_client_page(\Box_App $app, $page): string
{
$this->di['is_client_logged'];
$template = 'mod_client_' . $page;
return $app->render($template);
}
public function get_reset_password_confirm(\Box_App $app, $hash): string
{
$service = $this->di['mod_service']('client');
$this->di['events_manager']->fire(['event' => 'onBeforePasswordResetClient']);
$data = [
'hash' => $hash,
];
$template = 'mod_client_set_new_password';
// Call password_reset_valid function and if true, then render the template, otherwise redirect to the index page
$result = $service->password_reset_valid($data);
if ($result !== false) {
return $app->render($template);
} else {
$app->redirect('/');
}
}
}