mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-09 09:00:17 +02:00
1d3e99d2b2
* feat: user settings page (#182) - Settings link in the backoffice nav next to Logout - Language selector (Dutch only, noop save) - Change password form with current-password check - Change email form that re-triggers email confirmation - Resend confirmation email button for unconfirmed addresses - Disabled Download data button with Soon(tm) popover - Delete account with password confirmation modal, removes seasons the user is the sole owner of - Well-known URLs: change-password redirect and security.txt * feat: base security.txt Expires on the container build time The BUILD_TIME build arg is baked into the prod image as an env var and set by CI at image build. security.txt expires one year after the build, so the file goes stale when deployments stop. Dev and test fall back to one year from the request time. * refactor: extract shared controller functionality - AbstractController: authenticatedUser property hook and assertSameSeason() (moved from QuestionBankController) - EmailVerifier::sendDefaultConfirmation() replaces the duplicated confirmation email block in RegistrationController and SettingsController - QuizController: deduplicate candidate-data preparation into buildCandidateData() - Drop manual 422 status handling in QuizQuestionController, QuestionBankController and SettingsController: render() already returns 422 for submitted invalid forms passed as parameters * fix: address PR review comments - Catch UniqueConstraintViolationException when changing email to handle the race between the uniqueness check and the flush - Avoid else-only block in UserRepository::deleteUser - Align duplicate-email translation with the validators domain * fix: apply code-review findings for PR #191 - Invalidate outstanding ResetPasswordRequests after password or email change to close the account-takeover window (tokens otherwise remain valid) - Exclude the current user from email uniqueness check so submitting your own address no longer returns an error - Surface transport failures from sendDefaultConfirmation via a warning flash instead of silently showing success - Move Dockerfile ARG BUILD_TIME/ENV to after all build steps so changing the build timestamp no longer busts the composer/asset cache - Throw in prod when BUILD_TIME is missing (WellKnownController) so the security.txt Expires goes stale as intended when deployments stop; fall back to 'now' only in dev/test
60 lines
2.3 KiB
PHP
60 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tvdt\Controller;
|
|
|
|
use Safe\DateTimeImmutable;
|
|
use Safe\Exceptions\DatetimeException;
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
/** Serves well-known URIs (https://www.rfc-editor.org/rfc/rfc8615). */
|
|
final class WellKnownController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
#[Autowire(env: 'default::BUILD_TIME')]
|
|
private readonly ?string $buildTime,
|
|
#[Autowire(env: 'APP_ENV')]
|
|
private readonly string $appEnv,
|
|
) {}
|
|
|
|
/** @see https://w3c.github.io/webappsec-change-password-url/ */
|
|
#[Route('/.well-known/change-password', name: 'tvdt_well_known_change_password', methods: ['GET'])]
|
|
public function changePassword(): RedirectResponse
|
|
{
|
|
return $this->redirectToRoute('tvdt_backoffice_settings');
|
|
}
|
|
|
|
/**
|
|
* @see https://www.rfc-editor.org/rfc/rfc9116
|
|
*
|
|
* @throws DatetimeException
|
|
* @throws \Exception
|
|
*/
|
|
#[Route('/.well-known/security.txt', name: 'tvdt_well_known_security_txt', methods: ['GET'])]
|
|
public function securityTxt(): Response
|
|
{
|
|
// One year after the container build, so the file goes stale when deployments stop.
|
|
// In prod the build arg must be set; falling back to 'now' would renew Expires on every request,
|
|
// defeating the go-stale purpose. In dev/test 'now' is fine — no build bake happens there.
|
|
if ((null === $this->buildTime || '' === $this->buildTime) && 'prod' === $this->appEnv) {
|
|
throw new \LogicException('BUILD_TIME env var must be set in production (baked in during Docker build).');
|
|
}
|
|
|
|
$buildTime = (null !== $this->buildTime && '' !== $this->buildTime) ? $this->buildTime : 'now';
|
|
$expires = new DateTimeImmutable($buildTime)->modify('+1 year')->format(\DATE_RFC3339);
|
|
|
|
$content = <<<TXT
|
|
Contact: https://github.com/MarijnDoeve/TijdVoorDeTest/security/advisories/new
|
|
Expires: {$expires}
|
|
Preferred-Languages: nl, en
|
|
|
|
TXT;
|
|
|
|
return new Response($content, headers: ['Content-Type' => 'text/plain; charset=UTF-8']);
|
|
}
|
|
}
|