Implement api with ability to read snips and profile
This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user