Implement api with ability to read snips and profile

This commit is contained in:
Tim
2025-04-27 21:41:53 +02:00
parent ba00351201
commit f56c78f626
12 changed files with 267 additions and 20 deletions

View File

@ -2,8 +2,8 @@
namespace App\Controller;
use App\Entity\User;
use App\Form\ProfileType;
use App\Form\UserSettingsType;
use App\Service\LastRelease;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Uid\Uuid;
#[Route('/user', name: 'user')]
class UserController extends AbstractController
@ -58,4 +59,20 @@ class UserController extends AbstractController
'release' => $lastRelease,
]);
}
#[Route('/apikey/generate', name: '_apikey_generate')]
public function apiKeyGenerate(): Response
{
/** @var User $user */
$user = $this->getUser();
$apiKey = Uuid::v4()->toBase58();
$user->setApiKey($apiKey);
$this->em->persist($user);
$this->em->flush();
$this->addFlash('success', sprintf('Successfully generated new api key: "%s"', $apiKey));
return $this->redirectToRoute('user_profile');
}
}