1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Controller; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Form\Coach\EditUserForm; |
6
|
|
|
use Obblm\Core\Security\Roles; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
11
|
|
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @Route("/account", name="obblm_account") |
15
|
|
|
*/ |
16
|
|
|
class AccountController extends AbstractController |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @Route("/", name="") |
20
|
|
|
*/ |
21
|
|
|
public function editAccount(Request $request, UserPasswordEncoderInterface $passwordEncoder):Response |
22
|
|
|
{ |
23
|
|
|
$coach = $this->getUser(); |
24
|
|
|
$this->denyAccessUnlessGranted(Roles::COACH, $coach); |
25
|
|
|
|
26
|
|
|
$form = $this->createForm(EditUserForm::class, $this->getUser()); |
27
|
|
|
|
28
|
|
|
$form->handleRequest($request); |
29
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
30
|
|
|
$data = $form->getData(); |
31
|
|
|
if ($data->getPlainPassword()) { |
32
|
|
|
$password = $passwordEncoder->encodePassword($coach, $coach->getPlainPassword()); |
|
|
|
|
33
|
|
|
$coach->setPassword($password) |
34
|
|
|
->setHash(hash('sha256', $coach->getEmail())); |
35
|
|
|
} |
36
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
37
|
|
|
$entityManager->persist($coach); |
38
|
|
|
$entityManager->flush(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $this->render('@ObblmCore/account/edit.html.twig', [ |
42
|
|
|
'form' => $form->createView(), |
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|