1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dontdrinkandroot\Gitki\WebBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Dontdrinkandroot\Gitki\WebBundle\Entity\User; |
6
|
|
|
use Dontdrinkandroot\Gitki\WebBundle\Form\UserEditType; |
7
|
|
|
use Dontdrinkandroot\GitkiBundle\Controller\BaseController; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Philip Washington Sorst <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class UserController extends BaseController |
14
|
|
|
{ |
15
|
|
|
public function listAction() |
16
|
|
|
{ |
17
|
|
|
$this->assertAdmin(); |
18
|
|
|
$users = $this->get('fos_user.user_manager')->findUsers(); |
19
|
|
|
|
20
|
|
|
return $this->render('@DdrGitkiWeb/User/list.html.twig', ['users' => $users]); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function editAction(Request $request, $id) |
24
|
|
|
{ |
25
|
|
|
$this->assertAdmin(); |
26
|
|
|
|
27
|
|
|
$userManager = $this->get('fos_user.user_manager'); |
28
|
|
|
$newUser = false; |
29
|
|
|
if ('new' === $id) { |
30
|
|
|
$newUser = true; |
31
|
|
|
$user = $userManager->createUser(); |
32
|
|
|
} else { |
33
|
|
|
$userRepository = $this->get('doctrine')->getRepository(User::class); |
34
|
|
|
$user = $userRepository->find($id); |
35
|
|
|
if (null === $user) { |
36
|
|
|
throw $this->createNotFoundException(); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$form = $this->createForm(UserEditType::class, $user); |
41
|
|
|
$form->handleRequest($request); |
42
|
|
|
|
43
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
44
|
|
|
$userManager->updateUser($form->getData()); |
45
|
|
|
|
46
|
|
|
if ($newUser) { |
47
|
|
|
return $this->redirectToRoute('ddr_gitki.user.edit', ['id' => $user->getId()]); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->render('@DdrGitkiWeb/User/edit.html.twig', ['form' => $form->createView()]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function deleteAction($id) |
55
|
|
|
{ |
56
|
|
|
$this->assertAdmin(); |
57
|
|
|
|
58
|
|
|
$userRepository = $this->get('doctrine')->getRepository(User::class); |
59
|
|
|
/** @var User $user */ |
60
|
|
|
$user = $userRepository->find($id); |
61
|
|
|
if (null === $user) { |
62
|
|
|
throw $this->createNotFoundException(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$userManager = $this->get('fos_user.user_manager'); |
66
|
|
|
$userManager->deleteUser($user); |
67
|
|
|
|
68
|
|
|
return $this->redirectToRoute('ddr_gitki.user.list'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|