Fix hidden API token (#4828)

This commit is contained in:
Kevin Papst
2024-05-03 11:38:33 +02:00
committed by GitHub
parent 94d6b43dcc
commit 661bb16342
2 changed files with 11 additions and 9 deletions

View File

@@ -173,7 +173,7 @@ final class ProfileController extends AbstractController
$this->flashSuccess('action.update.success');
$request->getSession()->set('_show_access_token', $accessToken->getId());
return $this->redirectToRoute('user_profile_api_token', ['username' => $profile->getUserIdentifier()]);
return $this->redirectToRoute('user_profile_api_token', ['username' => $profile->getUserIdentifier(), 'hide-token' => '1']);
}
return $this->render('user/access-token.html.twig', [
@@ -207,13 +207,15 @@ final class ProfileController extends AbstractController
$accessTokens = $accessTokenRepository->findForUser($profile);
$createdToken = null;
$createdId = $request->getSession()->get('_show_access_token');
$request->getSession()->remove('_show_access_token');
if ($createdId !== null) {
foreach ($accessTokens as $accessToken) {
if ($accessToken->getId() === $createdId) {
$createdToken = $accessToken;
if (!$request->query->has('hide-token')) {
$createdId = $request->getSession()->get('_show_access_token');
$request->getSession()->remove('_show_access_token');
if ($createdId !== null) {
foreach ($accessTokens as $accessToken) {
if ($accessToken->getId() === $createdId) {
$createdToken = $accessToken;
}
}
}
}