updrade with rector
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Blog;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\SlugField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
/**
|
||||
* Class BlogCrudController
|
||||
* @package App\Controller\Admin
|
||||
*/
|
||||
class BlogCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Blog::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
return [
|
||||
AssociationField::new('author')
|
||||
->autocomplete(),
|
||||
TextField::new('title'),
|
||||
SlugField::new('slug')
|
||||
->setTargetFieldName('title'),
|
||||
TextEditorField::new('teaser'),
|
||||
TextEditorField::new('content'),
|
||||
DateTimeField::new('createdAt'),
|
||||
AssociationField::new('editedBy')
|
||||
->autocomplete()
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Comment;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
/**
|
||||
* Class CommentCrudController
|
||||
* @package App\Controller\Admin
|
||||
*/
|
||||
class CommentCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Comment::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
return [
|
||||
AssociationField::new('author')
|
||||
->autocomplete(),
|
||||
AssociationField::new('blog')
|
||||
->autocomplete(),
|
||||
TextField::new('title'),
|
||||
TextEditorField::new('content'),
|
||||
DateTimeField::new('createdAt'),
|
||||
AssociationField::new('editedBy')
|
||||
->autocomplete(),
|
||||
DateTimeField::new('editedAt'),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Pages;
|
||||
use App\Entity\Projects;
|
||||
use App\Entity\Quotes;
|
||||
use App\Entity\User;
|
||||
@@ -18,50 +19,45 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class DashboardController extends AbstractDashboardController
|
||||
{
|
||||
#[isGranted(data: 'ROLE_ADMIN')]
|
||||
#[Route(path: '/admin', name: 'admin')]
|
||||
public function index(): Response
|
||||
{
|
||||
//return parent::index();
|
||||
return $this->render(view: 'admin/index.html.twig');
|
||||
}
|
||||
|
||||
public function configureDashboard(): Dashboard
|
||||
{
|
||||
return Dashboard::new()
|
||||
->setTitle(title: '24unix Admin');
|
||||
}
|
||||
|
||||
public function configureMenuItems(): iterable
|
||||
{
|
||||
yield MenuItem::linkToUrl(label: 'Homepage', icon: 'fa fa-home', url: $this->generateUrl(route: 'app_main'));
|
||||
yield MenuItem::linkToDashboard(label: 'Dashboard', icon: 'fa fa-dashboard');
|
||||
yield MenuItem::linkToCrud(label: 'Projects', icon: 'fa fa-file-code-o', entityFqcn: Projects::class);
|
||||
yield MenuItem::linkToCrud(label: 'Users', icon: 'fa fa-users', entityFqcn: User::class);
|
||||
yield MenuItem::linkToCrud(label: 'Quotes', icon: 'fa fa-quote-left', entityFqcn: Quotes::class);
|
||||
}
|
||||
|
||||
public function configureUserMenu(UserInterface $user): UserMenu
|
||||
{
|
||||
if (!$user instanceof User) {
|
||||
throw new Exception(message: 'Wrong User!');
|
||||
}
|
||||
|
||||
return parent::configureUserMenu(user: $user)
|
||||
->setAvatarUrl(url: $user->getAvatar());
|
||||
}
|
||||
|
||||
|
||||
public function configureActions(): Actions
|
||||
{
|
||||
return parent::configureActions()
|
||||
->add(pageName: Crud::PAGE_INDEX, actionNameOrObject: Action::DETAIL);
|
||||
}
|
||||
|
||||
|
||||
#[isGranted(data: 'ROLE_ADMIN')]
|
||||
#[Route(path: '/admin', name: 'admin')]
|
||||
public function index(): Response
|
||||
{
|
||||
// return parent::index();
|
||||
return $this->render(view: 'admin/index.html.twig');
|
||||
}
|
||||
|
||||
public function configureDashboard(): Dashboard
|
||||
{
|
||||
return Dashboard::new()
|
||||
->setTitle(title: '24unix Admin');
|
||||
}
|
||||
|
||||
public function configureMenuItems(): iterable
|
||||
{
|
||||
yield MenuItem::linkToUrl(label: 'Homepage', icon: 'fa fa-home', url: $this->generateUrl(route: 'app_main'));
|
||||
yield MenuItem::linkToDashboard(label: 'Dashboard', icon: 'fa fa-dashboard');
|
||||
yield MenuItem::linkToCrud(label: 'Users', icon: 'fa fa-users', entityFqcn: User::class);
|
||||
yield MenuItem::linkToCrud(label: 'Projects', icon: 'fa fa-file-code-o', entityFqcn: Projects::class);
|
||||
yield MenuItem::linkToCrud(label: 'Pages', icon: 'fa fa-newspaper-o', entityFqcn: Pages::class);
|
||||
yield MenuItem::linkToCrud(label: 'Quotes', icon: 'fa fa-quote-left', entityFqcn: Quotes::class);
|
||||
}
|
||||
|
||||
public function configureUserMenu(UserInterface $user): UserMenu
|
||||
{
|
||||
if (!$user instanceof User) {
|
||||
throw new Exception(message: 'Wrong User!');
|
||||
}
|
||||
|
||||
return parent::configureUserMenu(user: $user)
|
||||
->setAvatarUrl(url: 'build/images/'.$user->getAvatar());
|
||||
}
|
||||
|
||||
public function configureActions(): Actions
|
||||
{
|
||||
return parent::configureActions()
|
||||
->add(pageName: Crud::PAGE_INDEX, actionNameOrObject: Action::DETAIL);
|
||||
}
|
||||
}
|
||||
|
||||
30
src/Controller/Admin/PagesCrudController.php
Normal file
30
src/Controller/Admin/PagesCrudController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Pages;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\CodeEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
class PagesCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Pages::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield IdField::new(propertyName: 'id')
|
||||
->onlyOnIndex();
|
||||
yield TextField::new(propertyName: 'name');
|
||||
yield AssociationField::new(propertyName: 'owner');
|
||||
// yield CodeEditorField::new(propertyName: 'content')
|
||||
yield TextareaField::new(propertyName: 'content')
|
||||
->onlyOnForms();
|
||||
}
|
||||
}
|
||||
@@ -8,27 +8,23 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProjectsCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Projects::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield IdField::new(propertyName: 'id')
|
||||
->onlyOnIndex();
|
||||
yield TextField::new(propertyName: 'name');
|
||||
yield TextField::new(propertyName: 'description');
|
||||
yield TextField::new(propertyName: 'description');
|
||||
yield ImageField::new(propertyName: 'teaserImage')
|
||||
->setBasePath(path: 'uploads/projects')
|
||||
->setUploadDir(uploadDirPath: 'public/uploads/projects')
|
||||
->setUploadedFileNamePattern(patternOrCallable: '[timestamp]-[slug].[extension]');
|
||||
|
||||
}
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Projects::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield IdField::new(propertyName: 'id')
|
||||
->onlyOnIndex();
|
||||
yield TextField::new(propertyName: 'name');
|
||||
yield TextField::new(propertyName: 'description');
|
||||
yield TextField::new(propertyName: 'description');
|
||||
yield ImageField::new(propertyName: 'teaserImage')
|
||||
->setBasePath(path: 'uploads/projects')
|
||||
->setUploadDir(uploadDirPath: 'public/uploads/projects')
|
||||
->setUploadedFileNamePattern(patternOrCallable: '[timestamp]-[slug].[extension]');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,23 +8,20 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class QuotesCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Quotes::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield IdField::new(propertyName: 'id')
|
||||
->onlyOnIndex();
|
||||
yield TextField::new(propertyName: 'quote')
|
||||
->onlyOnIndex();
|
||||
yield TextEditorField::new(propertyName: 'quote')
|
||||
->onlyOnForms();
|
||||
}
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Quotes::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield IdField::new(propertyName: 'id')
|
||||
->onlyOnIndex();
|
||||
yield TextField::new(propertyName: 'quote')
|
||||
->onlyOnIndex();
|
||||
yield TextEditorField::new(propertyName: 'quote')
|
||||
->onlyOnForms();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Section;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
|
||||
/**
|
||||
* Class SectionCrudController
|
||||
* @package App\Controller\Admin
|
||||
*/
|
||||
class SectionCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Section::class;
|
||||
}
|
||||
|
||||
/*
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
return [
|
||||
IdField::new('id'),
|
||||
TextField::new('title'),
|
||||
TextEditorField::new('description'),
|
||||
];
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -10,9 +10,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class UserCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
@@ -22,20 +19,20 @@ class UserCrudController extends AbstractCrudController
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield IdField::new(propertyName: 'id')
|
||||
->onlyOnIndex();
|
||||
yield TextField::new(propertyName: 'firstName');
|
||||
yield TextField::new(propertyName: 'lastName');
|
||||
yield EmailField::new(propertyName: 'email');
|
||||
yield ImageField::new(propertyName: 'avatar')
|
||||
->setBasePath(path: 'uploads/avatars')
|
||||
->setUploadDir(uploadDirPath: 'public/uploads/avatars')
|
||||
->setUploadedFileNamePattern(patternOrCallable: '[timestamp]-[slug].[extension]');
|
||||
$roles = ['ROLE_FOUNDER', 'ROLE_ADMIN', 'ROLE_MODERATOR', 'ROLE_USER'];
|
||||
yield ChoiceField::new(propertyName: 'roles')
|
||||
->setChoices(choiceGenerator: array_combine(keys: $roles, values: $roles))
|
||||
->allowMultipleChoices()
|
||||
->renderExpanded()
|
||||
->renderAsBadges();
|
||||
yield IdField::new(propertyName: 'id')
|
||||
->onlyOnIndex();
|
||||
yield TextField::new(propertyName: 'firstName');
|
||||
yield TextField::new(propertyName: 'lastName');
|
||||
yield EmailField::new(propertyName: 'email');
|
||||
yield ImageField::new(propertyName: 'avatar')
|
||||
->setBasePath(path: 'uploads/avatars')
|
||||
->setUploadDir(uploadDirPath: 'public/uploads/avatars')
|
||||
->setUploadedFileNamePattern(patternOrCallable: '[timestamp]-[slug].[extension]');
|
||||
$roles = ['ROLE_FOUNDER', 'ROLE_ADMIN', 'ROLE_MODERATOR', 'ROLE_USER'];
|
||||
yield ChoiceField::new(propertyName: 'roles')
|
||||
->setChoices(choiceGenerator: array_combine(keys: $roles, values: $roles))
|
||||
->allowMultipleChoices()
|
||||
->renderExpanded()
|
||||
->renderAsBadges();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Blog;
|
||||
use App\Form\BlogFormType;
|
||||
use App\Repository\BlogRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Class BlogController
|
||||
* @package App\Controller
|
||||
*/
|
||||
class BlogController extends AbstractController
|
||||
{
|
||||
#[Route('/', name: 'blogs')]
|
||||
public function index(BlogRepository $blogRepository): Response
|
||||
{
|
||||
return $this->render('blog/index.html.twig', [
|
||||
'blogs' => $blogRepository->findAll()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $slug
|
||||
* @param \App\Repository\BlogRepository $blogRepository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route('/blog_show/{slug}', name: 'blog')]
|
||||
public function show($slug, BlogRepository $blogRepository): Response
|
||||
{
|
||||
return $this->render('blog/show.html.twig', [
|
||||
'blog' => $blogRepository->findOneBy(['slug' => $slug])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\ORM\EntityManagerInterface $entityManager
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route('/blog/new', name: 'blog_new')]
|
||||
public function new(EntityManagerInterface $entityManager, Request $request): RedirectResponse|Response
|
||||
{
|
||||
$form = $this->createForm(BlogFormType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$blog = $form->getData();
|
||||
$entityManager->persist($blog);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('blogs');
|
||||
}
|
||||
return $this->render('blog/new.html.twig', [
|
||||
'blogForm' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Entity\Blog $blog
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route('/blog/edit/{id}', name: 'blog_edit')]
|
||||
public function edit(Blog $blog, Request $request): Response|RedirectResponse
|
||||
{
|
||||
$form = $this->createForm(BlogFormType::class, $blog);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$blog = $form->getData();
|
||||
//$blog->setAuthor($this->getUser());
|
||||
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($blog);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('blogs');
|
||||
}
|
||||
return $this->render('blog/new.html.twig', [
|
||||
'blogForm' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
33
src/Controller/FrontendController.php
Normal file
33
src/Controller/FrontendController.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
// src/Controller/FrontendController.php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\QuotesRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class FrontendController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(path: '/', name: 'app_main')]
|
||||
#[Route(path: '/{route}', name: 'vue_pages', requirements: ['route' => '^(?!.*_wdt|_profiler|login|logout).+'] )]
|
||||
|
||||
public function quote(SerializerInterface $serializer, QuotesRepository $quotesRepository): Response
|
||||
{
|
||||
$quote = $quotesRepository->findOneRandom();
|
||||
|
||||
return $this->render(view: 'base.html.twig', parameters: [
|
||||
'user' => $serializer->serialize(data: $this->getUser(), format: 'jsonld'),
|
||||
'quote' => json_encode(value: $quote->getQuote())
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
// src/Controller/LuckyController.php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\QuotesRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class MainController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(path: '/', name: 'app_main')]
|
||||
public function quote(QuotesRepository $quotesRepository): Response
|
||||
{
|
||||
|
||||
$quote = $quotesRepository->findOneRandom();
|
||||
|
||||
return $this->render(view: 'base.html.twig', parameters: [
|
||||
'quote' => $quote->getQuote()
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,28 +2,29 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Pages;
|
||||
use App\Repository\PagesRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class PagesController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/imprint', name: 'app_imprint')]
|
||||
public function imprint(): Response
|
||||
#[Route(path: '/pages/{name}', name: 'pages_display')]
|
||||
public function display(PagesRepository $pagesRepository, string $name): Response
|
||||
{
|
||||
return $this->render(view: 'pages/imprint.html.twig', parameters: [
|
||||
'controller_name' => 'PagesController',
|
||||
$page = $pagesRepository->findOneBy([
|
||||
'slug' => $name,
|
||||
]);
|
||||
|
||||
if (!$page) {
|
||||
$page = new Pages();
|
||||
$page->setName(name: 'Not Found');
|
||||
$page->setContent(content: 'The requested page was not found.');
|
||||
}
|
||||
|
||||
return $this->render(view: 'pages/display.html.twig', parameters: [
|
||||
'page' => $page,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/privacy', name: 'app_privacy')]
|
||||
public function privacy(): Response
|
||||
{
|
||||
return $this->render(view: 'pages/privacy.html.twig', parameters: [
|
||||
'controller_name' => 'PagesController',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,36 +2,33 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\ProjectsRepository;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use App\Repository\ProjectsRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProjectsController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/projects/{name}', name: 'app_projects')]
|
||||
public function index(ProjectsRepository $projectsRepository, string $name = ''): Response
|
||||
{
|
||||
if ($name == '') {
|
||||
return $this->render(view: 'projects/index.html.twig', parameters: [
|
||||
'projects' => $projectsRepository->findAll()
|
||||
]);
|
||||
} else {
|
||||
if ($project = $projectsRepository->findOneByName(value: $name)) {
|
||||
$readMe = file_get_contents(filename: $project->getURL() . '/raw/branch/master/README.md');
|
||||
|
||||
//$parsedReadMe = $markdownParser->transformMarkdown(text: $readMe);
|
||||
|
||||
return $this->render(view: 'projects/show.html.twig', parameters: [
|
||||
'project' => $project,
|
||||
'readme' => $readMe
|
||||
]);
|
||||
} else {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[Route(path: '/projects/{name}', name: 'app_projects')]
|
||||
public function index(ProjectsRepository $projectsRepository, string $name = ''): Response
|
||||
{
|
||||
if ($name == '') {
|
||||
return $this->render(view: 'projects/index.html.twig', parameters: [
|
||||
'projects' => $projectsRepository->findAll(),
|
||||
]);
|
||||
} else {
|
||||
if ($project = $projectsRepository->findOneByName(value: $name)) {
|
||||
$readMe = file_get_contents(filename: $project->getURL().'/raw/branch/master/README.md');
|
||||
|
||||
// $parsedReadMe = $markdownParser->transformMarkdown(text: $readMe);
|
||||
|
||||
return $this->render(view: 'projects/show.html.twig', parameters: [
|
||||
'project' => $project,
|
||||
'readme' => $readMe,
|
||||
]);
|
||||
} else {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\RegistrationFormType;
|
||||
use App\Security\EmailVerifier;
|
||||
use App\Repository\UserRepository;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
|
||||
|
||||
/**
|
||||
* Class RegistrationController
|
||||
* @package App\Controller
|
||||
*/
|
||||
class RegistrationController extends AbstractController
|
||||
{
|
||||
private $emailVerifier;
|
||||
|
||||
public function __construct(EmailVerifier $emailVerifier)
|
||||
{
|
||||
$this->emailVerifier = $emailVerifier;
|
||||
}
|
||||
|
||||
#[Route('/register', name: 'app_register')]
|
||||
public function register(Request $request, UserPasswordHasherInterface $passwordHasher): Response
|
||||
{
|
||||
$user = new User();
|
||||
$form = $this->createForm(RegistrationFormType::class, $user);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// hash the plain password
|
||||
$user->setPassword(
|
||||
$passwordHasher->hashPassword(
|
||||
$user,
|
||||
$form->get('plainPassword')->getData()
|
||||
)
|
||||
);
|
||||
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($user);
|
||||
$entityManager->flush();
|
||||
|
||||
// generate a signed url and email it to the user
|
||||
$this->emailVerifier->sendEmailConfirmation('app_verify_email', $user,
|
||||
(new TemplatedEmail())
|
||||
->from(new Address('tracer@24unix.net', '24unix'))
|
||||
->to($user->getEmail())
|
||||
->subject('Please Confirm your Email')
|
||||
->htmlTemplate('registration/confirmation_email.html.twig')
|
||||
);
|
||||
// do anything else you need here, like send an email
|
||||
|
||||
return $this->redirectToRoute('blogs');
|
||||
}
|
||||
|
||||
return $this->render('security/register.html.twig', [
|
||||
'registrationForm' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/verify/email', name: 'app_verify_email')]
|
||||
public function verifyUserEmail(Request $request, UserRepository $userRepository): Response
|
||||
{
|
||||
$id = $request->get('id');
|
||||
|
||||
if ($id === null) {
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
$user = $userRepository->find($id);
|
||||
|
||||
if ($user === null) {
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
// validate email confirmation link, sets User::isVerified=true and persists
|
||||
try {
|
||||
$this->emailVerifier->handleEmailConfirmation($request, $user);
|
||||
} catch (VerifyEmailExceptionInterface $exception) {
|
||||
$this->addFlash('verify_email_error', $exception->getReason());
|
||||
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
// @TODO Change the redirect on success and handle or remove the flash message in your templates
|
||||
$this->addFlash('success', 'Your email address has been verified.');
|
||||
|
||||
return $this->redirectToRoute('blogs');
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\ChangePasswordFormType;
|
||||
use App\Form\ResetPasswordRequestFormType;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
|
||||
use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface;
|
||||
use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
|
||||
|
||||
/**
|
||||
* Class ResetPasswordController
|
||||
* @package App\Controller
|
||||
*/
|
||||
#[Route('/reset-password')]
|
||||
class ResetPasswordController extends AbstractController
|
||||
{
|
||||
use ResetPasswordControllerTrait;
|
||||
|
||||
private $resetPasswordHelper;
|
||||
|
||||
public function __construct(ResetPasswordHelperInterface $resetPasswordHelper)
|
||||
{
|
||||
$this->resetPasswordHelper = $resetPasswordHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display & process form to request a password reset.
|
||||
*/
|
||||
#[Route('', name: 'app_forgot_password_request')]
|
||||
public function request(Request $request, MailerInterface $mailer): Response
|
||||
{
|
||||
$form = $this->createForm(ResetPasswordRequestFormType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
return $this->processSendingPasswordResetEmail(
|
||||
$form->get('email')->getData(),
|
||||
$mailer
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('security/request.html.twig', [
|
||||
'requestForm' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirmation page after a user has requested a password reset.
|
||||
*/
|
||||
#[Route('/check-email', name: 'app_check_email')]
|
||||
public function checkEmail(): Response
|
||||
{
|
||||
// Generate a fake token if the user does not exist or someone hit this page directly.
|
||||
// This prevents exposing whether or not a user was found with the given email address or not
|
||||
if (null === ($resetToken = $this->getTokenObjectFromSession())) {
|
||||
$resetToken = $this->resetPasswordHelper->generateFakeResetToken();
|
||||
}
|
||||
|
||||
return $this->render('security/check_email.html.twig', [
|
||||
'resetToken' => $resetToken,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and process the reset URL that the user clicked in their email.
|
||||
*/
|
||||
#[Route('/reset/{token}', name: 'app_reset_password')]
|
||||
public function reset(Request $request, UserPasswordHasherInterface $passwordHasher, string $token = null): Response
|
||||
{
|
||||
if ($token) {
|
||||
// We store the token in session and remove it from the URL, to avoid the URL being
|
||||
// loaded in a browser and potentially leaking the token to 3rd party JavaScript.
|
||||
$this->storeTokenInSession($token);
|
||||
|
||||
return $this->redirectToRoute('app_reset_password');
|
||||
}
|
||||
|
||||
$token = $this->getTokenFromSession();
|
||||
if ($token === null) {
|
||||
throw $this->createNotFoundException('No reset password token found in the URL or in the session.');
|
||||
}
|
||||
|
||||
try {
|
||||
$user = $this->resetPasswordHelper->validateTokenAndFetchUser($token);
|
||||
} catch (ResetPasswordExceptionInterface $e) {
|
||||
$this->addFlash('reset_password_error', sprintf(
|
||||
'There was a problem validating your reset request - %s',
|
||||
$e->getReason()
|
||||
));
|
||||
|
||||
return $this->redirectToRoute('app_forgot_password_request');
|
||||
}
|
||||
|
||||
// The token is valid; allow the user to change their password.
|
||||
$form = $this->createForm(ChangePasswordFormType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// A password reset token should be used only once, remove it.
|
||||
$this->resetPasswordHelper->removeResetRequest($token);
|
||||
|
||||
// Hash the plain password, and set it.
|
||||
/*
|
||||
** @var PasswordAuthenticatedUserInterface $user
|
||||
*/
|
||||
$hashedPassword = $passwordHasher->hashPassword(
|
||||
$user,
|
||||
$form->get('plainPassword')->getData()
|
||||
);
|
||||
|
||||
$user->setPassword($hashedPassword);
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
// The session is cleaned up after the password has been changed.
|
||||
$this->cleanSessionAfterReset();
|
||||
|
||||
return $this->redirectToRoute('blogs');
|
||||
}
|
||||
|
||||
return $this->render('security/reset.html.twig', [
|
||||
'resetForm' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse
|
||||
{
|
||||
$user = $this->getDoctrine()->getRepository(User::class)->findOneBy([
|
||||
'email' => $emailFormData,
|
||||
]);
|
||||
|
||||
// Do not reveal whether a user account was found or not.
|
||||
if (!$user) {
|
||||
return $this->redirectToRoute('app_check_email');
|
||||
}
|
||||
|
||||
try {
|
||||
$resetToken = $this->resetPasswordHelper->generateResetToken($user);
|
||||
} catch (ResetPasswordExceptionInterface $e) {
|
||||
// If you want to tell the user why a reset email was not sent, uncomment
|
||||
// the lines below and change the redirect to 'app_forgot_password_request'.
|
||||
// Caution: This may reveal if a user is registered or not.
|
||||
//
|
||||
// $this->addFlash('reset_password_error', sprintf(
|
||||
// 'There was a problem handling your password reset request - %s',
|
||||
// $e->getReason()
|
||||
// ));
|
||||
|
||||
return $this->redirectToRoute('app_check_email');
|
||||
}
|
||||
|
||||
$email = (new TemplatedEmail())
|
||||
->from(new Address('tracer@24unix.net', '24unix.net'))
|
||||
->to($user->getEmail())
|
||||
->subject('Your password reset request')
|
||||
->htmlTemplate('security/email.html.twig')
|
||||
->context([
|
||||
'resetToken' => $resetToken,
|
||||
]);
|
||||
|
||||
$mailer->send($email);
|
||||
|
||||
// Store the token object in session for retrieval in check-email route.
|
||||
$this->setTokenObjectInSession($resetToken);
|
||||
|
||||
return $this->redirectToRoute('app_check_email');
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,44 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use ApiPlatform\Core\Api\IriConverterInterface;
|
||||
use App\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/login', name: 'app_login')]
|
||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||
#[Route(path: '/login', name: 'app_login')] // *** method post
|
||||
public function login(AuthenticationUtils $authenticationUtils, IriConverterInterface $iriConverter): Response
|
||||
{
|
||||
|
||||
if (!$this->isGranted(attribute: 'IS_AUTHENTICATED_FULLY')) {
|
||||
return $this->json(data: [
|
||||
'error' => 'Invalid login request'
|
||||
], status: 400);
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser() ?? null;
|
||||
|
||||
return new Response(content: null, status: 204, headers: [
|
||||
'Location' => $iriConverter->getIriFromItem(item: $user)
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
return $this->render(view: 'security/login.html.twig', parameters: [
|
||||
'error' => $authenticationUtils->getLastAuthenticationError(),
|
||||
'last_username' => $authenticationUtils->getLastUsername(),
|
||||
]);
|
||||
*
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,65 +11,78 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||
|
||||
/**
|
||||
* Class UserController
|
||||
* @package App\Controller
|
||||
* Class UserController.
|
||||
*/
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @param \App\Repository\UserRepository $userRepository
|
||||
* @param string $userName
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route(path: '/profile/edit/{username}', name: 'app_profile_edit')]
|
||||
public function editProfile(UserRepository $userRepository, string $username = ''): Response
|
||||
{
|
||||
/** var User $user */
|
||||
if ($username === '') {
|
||||
if ($this->isGranted(attribute: 'ROLE_USER')) {
|
||||
$user = $this->getUser();
|
||||
} else {
|
||||
throw new AccessDeniedException(message: 'You need to be logged in.');
|
||||
}
|
||||
} else {
|
||||
if ($this->isGranted(attribute: 'ROLE_ADMIN')) {
|
||||
$user = $userRepository->findOneBy([
|
||||
"username" => $username
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($user)) {
|
||||
return $this->render(view: 'user/edit_profile.html.twig', parameters: [
|
||||
'user' => $user,
|
||||
]);
|
||||
} else {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Repository\UserRepository $userRepository
|
||||
* @param string $username
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route(path: '/profile/{username}', name: 'app_profile')]
|
||||
public function showProfile(UserRepository $userRepository, string $username = ''): Response
|
||||
{
|
||||
/** var User $user */
|
||||
if ($username === '') {
|
||||
$user = $this->getUser();
|
||||
} else {
|
||||
$user = $userRepository->findOneBy([
|
||||
"username" => $username
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render(view: 'user/show_profile.html.twig', parameters: [
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Repository\UserRepository $userRepository
|
||||
* @param string $userName
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route(path: '/profile/edit/{username}', name: 'app_profile_edit')]
|
||||
public function editProfile(UserRepository $userRepository, string $username = ''): Response
|
||||
{
|
||||
/* var User $user */
|
||||
if ($username === '') {
|
||||
if ($this->isGranted(attribute: 'ROLE_USER')) {
|
||||
$user = $this->getUser();
|
||||
} else {
|
||||
throw new AccessDeniedException(message: 'You need to be logged in.');
|
||||
}
|
||||
} else {
|
||||
if ($this->isGranted(attribute: 'ROLE_ADMIN')) {
|
||||
$user = $userRepository->findOneBy([
|
||||
'username' => $username,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($user)) {
|
||||
return $this->render(view: 'user/edit_profile.html.twig', parameters: [
|
||||
'user' => $user,
|
||||
]);
|
||||
} else {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Repository\UserRepository $userRepository
|
||||
* @param string $username
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route(path: '/profile/{username}', name: 'app_profile')]
|
||||
public function showProfile(UserRepository $userRepository, string $username = ''): Response
|
||||
{
|
||||
/* var User $user */
|
||||
if ($username === '') {
|
||||
$user = $this->getUser();
|
||||
} else {
|
||||
$user = $userRepository->findOneBy([
|
||||
'username' => $username,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render(view: 'user/show_profile.html.twig', parameters: [
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Repository\UserRepository $userRepository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
#[Route(path: '/list_users/', name: 'app_list_user')]
|
||||
public function listUsers(UserRepository $userRepository): Response
|
||||
{
|
||||
$users = $userRepository->findAll();
|
||||
|
||||
return $this->render(view: 'user/list_users.html.twig', parameters: [
|
||||
'users' => $users,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user