|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fi\CoreBundle\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use Fi\CoreBundle\Controller\FiController; |
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
7
|
|
|
use Fi\CoreBundle\Utils\Tabella\ParametriTabella; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
9
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
10
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
|
13
|
|
|
use Psr\Log\LoggerInterface; |
|
14
|
|
|
use Doctrine\Common\Persistence\ObjectManager ; |
|
15
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Operatori controller. |
|
19
|
|
|
*/ |
|
20
|
|
|
class OperatoriController extends FiController |
|
21
|
|
|
{ |
|
22
|
|
|
private $logger; |
|
23
|
|
|
private $usermanipulator; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct(ObjectManager $em, TokenStorageInterface $user, LoggerInterface $logger, $usermanipulator) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->logger = $logger; |
|
|
|
|
|
|
28
|
|
|
$this->usermanipulator = $usermanipulator; |
|
29
|
|
|
parent::__construct($em, $user); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Displays a form to create a new table entity. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function new(Request $request) |
|
36
|
|
|
{ |
|
37
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
38
|
|
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
39
|
|
|
$controller = $this->getController(); |
|
40
|
|
|
if (!$this->getPermessi()->canCreate()) { |
|
41
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto"); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
$template = $bundle . ':' . $controller . ':' . $this->getThisFunctionName() . '.html.twig'; |
|
44
|
|
|
if (!$this->get('templating')->exists($template)) { |
|
45
|
|
|
$template = $controller . '/Crud/' . $this->getThisFunctionName() . '.html.twig'; |
|
46
|
|
|
} |
|
47
|
|
|
$entityclass = $this->getEntityClassName(); |
|
48
|
|
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$entity = new $entityclass(); |
|
|
|
|
|
|
51
|
|
|
$formType = $formclass . 'Type'; |
|
52
|
|
|
$form = $this->createForm($formType, $entity, array('attr' => array( |
|
|
|
|
|
|
53
|
|
|
'id' => 'formdati' . $controller, |
|
54
|
|
|
), |
|
55
|
|
|
'action' => $this->generateUrl($controller . '_new'), |
|
56
|
|
|
)); |
|
57
|
|
|
|
|
58
|
|
|
$form->handleRequest($request); |
|
59
|
|
|
|
|
60
|
|
|
$twigparms = array( |
|
61
|
|
|
'form' => $form->createView(), |
|
62
|
|
|
'nomecontroller' => ParametriTabella::setParameter($controller) |
|
63
|
|
|
); |
|
64
|
|
|
if ($form->isSubmitted()) { |
|
65
|
|
|
if ($form->isValid()) { |
|
66
|
|
|
$logger = $this->logger; |
|
|
|
|
|
|
67
|
|
|
$entity = $form->getData(); |
|
|
|
|
|
|
68
|
|
|
$username = $entity->getUsername(); |
|
69
|
|
|
$password = $entity->getPassword(); |
|
70
|
|
|
$logger->info('Inserimento nuovo utente ' . $username); |
|
71
|
|
|
|
|
72
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
73
|
|
|
$entityManager->persist($entity); |
|
74
|
|
|
$entityManager->flush(); |
|
75
|
|
|
|
|
76
|
|
|
$content = $this->usermanipulator->changePassword($username, $password); |
|
77
|
|
|
|
|
78
|
|
|
$logger->info('Esito inserimento nuovo utente ' . $username . " : " . $content); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
return new Response( |
|
81
|
|
|
$this->renderView($template, $twigparms), |
|
82
|
|
|
200 |
|
83
|
|
|
); |
|
84
|
|
|
} else { |
|
85
|
|
|
//Quando non passa la validazione |
|
86
|
|
|
return new Response( |
|
87
|
|
|
$this->renderView($template, $twigparms), |
|
88
|
|
|
400 |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
} else { |
|
92
|
|
|
//Quando viene richiesta una "nuova" new |
|
93
|
|
|
return new Response( |
|
94
|
|
|
$this->renderView($template, $twigparms), |
|
95
|
|
|
200 |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.