|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\FormRequest; |
|
6
|
|
|
use AppBundle\Entity\Survey\Survey; |
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use AppBundle\Entity\User; |
|
13
|
|
|
|
|
14
|
|
|
class DefaultController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/", name="homepage") |
|
18
|
|
|
* @Template("@App/dashboard.html.twig") |
|
19
|
|
|
*/ |
|
20
|
|
|
public function indexAction() |
|
21
|
|
|
{ |
|
22
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
23
|
|
|
|
|
24
|
|
|
$surveys = $em->getRepository(Survey::class)->selectLastSurveys(); |
|
25
|
|
|
$requestForms = $em->getRepository(FormRequest::class)->selectLastRequestForms(); |
|
26
|
|
|
|
|
27
|
|
|
return [ |
|
28
|
|
|
'surveys' => $surveys, |
|
29
|
|
|
'requestForms' => $requestForms, |
|
30
|
|
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @Route("/schedule", name="calendar") |
|
35
|
|
|
* @Template("@App/schedules.html.twig") |
|
36
|
|
|
*/ |
|
37
|
|
|
public function calendarAction() |
|
38
|
|
|
{ |
|
39
|
|
|
return []; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @Route("/login", name="login") |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
* @Method({"GET", "POST"}) |
|
47
|
|
|
* @Template("@App/login.html.twig") |
|
48
|
|
|
*/ |
|
49
|
6 |
|
public function loginAction() |
|
50
|
|
|
{ |
|
51
|
6 |
|
$authenticationUtils = $this->get('security.authentication_utils'); |
|
52
|
6 |
|
$error = $authenticationUtils->getLastAuthenticationError(); |
|
53
|
6 |
|
$lastUsername = $authenticationUtils->getLastUsername(); |
|
54
|
|
|
|
|
55
|
|
|
return [ |
|
56
|
6 |
|
'last_username' => $lastUsername, //$lastUsername, |
|
57
|
6 |
|
'error' => $error, |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param Request $request, string $token |
|
|
|
|
|
|
63
|
|
|
* @Route("/password_update/{token}", name="password_update") |
|
64
|
|
|
* @Template("@App/User/update_password.html.twig") |
|
65
|
|
|
* @Method({"GET", "POST"}) |
|
66
|
|
|
* |
|
67
|
|
|
* @return array |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public function updatePasswordAction(Request $request, $token) |
|
70
|
|
|
{ |
|
71
|
1 |
|
$user = $this->getDoctrine()->getRepository(User::class)->loadUserByToken($token); |
|
72
|
1 |
|
if ((!$user)) { |
|
73
|
|
|
return ['message' => 'Your link is expired!']; |
|
74
|
|
|
} |
|
75
|
1 |
|
$linkDate = $user->getLinkExpiredAt(); |
|
76
|
1 |
|
$date = new \DateTime('now'); |
|
77
|
1 |
|
if (($linkDate < $date)) { |
|
78
|
|
|
return ['message' => 'Your link is expired!']; |
|
79
|
|
|
} |
|
80
|
1 |
|
$form = $this->createForm(\AppBundle\Form\User\ResetPasswordType::class, $user); |
|
81
|
1 |
|
$form->handleRequest($request); |
|
82
|
|
|
|
|
83
|
1 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
84
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
|
85
|
1 |
|
$encoder = $this->get('security.password_encoder'); |
|
86
|
1 |
|
$user->setPassword($encoder->encodePassword($user, $user->getPlainPassword())); |
|
87
|
1 |
|
$em->persist($user); |
|
88
|
1 |
|
$em->flush(); |
|
89
|
|
|
|
|
90
|
1 |
|
return ['message' => 'Your password was successfully updated!', 'user' => $user]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
return ['message' => 'Please, enter your new password', 'form' => $form->createView()]; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.