more stuff

This commit is contained in:
Skylar Sadlier 2024-02-09 19:32:41 -07:00
parent d76c0d31f9
commit 4a1c6e1a72
12 changed files with 249 additions and 1 deletions

10
.editorconfig Normal file
View File

@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2

2
.yarnrc.yml Normal file
View File

@ -0,0 +1,2 @@
yarnPath: .yarn/releases/yarn-3.6.3.cjs
nodeLinker: node-modules

View File

@ -10,8 +10,10 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
#[Route('/page')] #[Route('/page')]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
class PageController extends AbstractController class PageController extends AbstractController
{ {
#[Route('/', name: 'app_page_index', methods: ['GET'])] #[Route('/', name: 'app_page_index', methods: ['GET'])]

View File

@ -0,0 +1,81 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\UserType;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/user')]
class UserController extends AbstractController
{
#[Route('/', name: 'app_user_index', methods: ['GET'])]
public function index(UserRepository $userRepository): Response
{
return $this->render('user/index.html.twig', [
'users' => $userRepository->findAll(),
]);
}
#[Route('/new', name: 'app_user_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$user = new User();
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($user);
$entityManager->flush();
return $this->redirectToRoute('app_user_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('user/new.html.twig', [
'user' => $user,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_user_show', methods: ['GET'])]
public function show(User $user): Response
{
return $this->render('user/show.html.twig', [
'user' => $user,
]);
}
#[Route('/{id}/edit', name: 'app_user_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, User $user, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_user_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('user/edit.html.twig', [
'user' => $user,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_user_delete', methods: ['POST'])]
public function delete(Request $request, User $user, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->request->get('_token'))) {
$entityManager->remove($user);
$entityManager->flush();
}
return $this->redirectToRoute('app_user_index', [], Response::HTTP_SEE_OTHER);
}
}

30
src/Form/UserType.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email')
->add('displayName')
->add('roles')
->add('password')
->add('createdAt')
->add('updatedAt')
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}

View File

@ -40,7 +40,7 @@
<i class="fas fa-file fa-fw me-3"></i> <i class="fas fa-file fa-fw me-3"></i>
<span>Pages</span> <span>Pages</span>
</a> </a>
<a href="#" class="list-group-item list-group-item-action py-2 ripple"> <a href="#" class="list-group-item list-group-item-action py-2 ripple{{ app.request.pathInfo starts with path('app_user_index') ? ' active' : ''}}">
<i class="fas fa-users fa-fw me-3"></i> <i class="fas fa-users fa-fw me-3"></i>
<span>Users</span> <span>Users</span>
</a> </a>

View File

@ -0,0 +1,4 @@
<form method="post" action="{{ path('app_user_delete', {'id': user.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ user.id) }}">
<button class="btn">Delete</button>
</form>

View File

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View File

@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}Edit User{% endblock %}
{% block body %}
<h1>Edit User</h1>
{{ include('user/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('app_user_index') }}">back to list</a>
{{ include('user/_delete_form.html.twig') }}
{% endblock %}

View File

@ -0,0 +1,45 @@
{% extends 'base.html.twig' %}
{% block title %}User index{% endblock %}
{% block body %}
<h1>User index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Email</th>
<th>DisplayName</th>
<th>Roles</th>
<th>Password</th>
<th>CreatedAt</th>
<th>UpdatedAt</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.id }}</td>
<td>{{ user.email }}</td>
<td>{{ user.displayName }}</td>
<td>{{ user.roles ? user.roles|json_encode : '' }}</td>
<td>{{ user.password }}</td>
<td>{{ user.createdAt ? user.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ user.updatedAt ? user.updatedAt|date('Y-m-d H:i:s') : '' }}</td>
<td>
<a href="{{ path('app_user_show', {'id': user.id}) }}">show</a>
<a href="{{ path('app_user_edit', {'id': user.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="8">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('app_user_new') }}">Create new</a>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New User{% endblock %}
{% block body %}
<h1>Create new User</h1>
{{ include('user/_form.html.twig') }}
<a href="{{ path('app_user_index') }}">back to list</a>
{% endblock %}

View File

@ -0,0 +1,46 @@
{% extends 'base.html.twig' %}
{% block title %}User{% endblock %}
{% block body %}
<h1>User</h1>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<td>{{ user.id }}</td>
</tr>
<tr>
<th>Email</th>
<td>{{ user.email }}</td>
</tr>
<tr>
<th>DisplayName</th>
<td>{{ user.displayName }}</td>
</tr>
<tr>
<th>Roles</th>
<td>{{ user.roles ? user.roles|json_encode : '' }}</td>
</tr>
<tr>
<th>Password</th>
<td>{{ user.password }}</td>
</tr>
<tr>
<th>CreatedAt</th>
<td>{{ user.createdAt ? user.createdAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
<tr>
<th>UpdatedAt</th>
<td>{{ user.updatedAt ? user.updatedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
</tbody>
</table>
<a href="{{ path('app_user_index') }}">back to list</a>
<a href="{{ path('app_user_edit', {'id': user.id}) }}">edit</a>
{{ include('user/_delete_form.html.twig') }}
{% endblock %}