Completed
Pull Request — master (#30)
by Yuriy
37:30 queued 22:07
created

DefaultController::updatePasswordAction()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
ccs 1
cts 1
cp 1
rs 8.439
cc 5
eloc 18
nc 4
nop 2
crap 5
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
        return [
27
            'surveys' => $surveys,
28
            'requestForms' => $requestForms,
29
        ];
30 6
    }
31
32 6
    /**
33 6
     * @Route("/schedule", name="calendar")
34 6
     * @Template("@App/schedules.html.twig")
35
     */
36
    public function calendarAction()
37 6
    {
38 6
        return [];
39
    }
40
41
    /**
42
     * @Route("/login", name="login")
43
     *
44
     * @return array
45
     * @Method({"GET", "POST"})
46
     * @Template("@App/login.html.twig")
47
     */
48
    public function loginAction()
49
    {
50 1
        $authenticationUtils = $this->get('security.authentication_utils');
51
        $error = $authenticationUtils->getLastAuthenticationError();
52 1
        $lastUsername = $authenticationUtils->getLastUsername();
53 1
54
        return [
55
            'last_username' => $lastUsername, //$lastUsername,
56 1
            'error' => $error,
57 1
        ];
58 1
    }
59
60
    /**
61 1
     * @param Request $request, string $token
0 ignored issues
show
Documentation introduced by
There is no parameter named $request,. Did you maybe mean $request?

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 $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
62 1
     * @Route("/password_update/{token}", name="password_update")
63
     * @Template("@App/User/update_password.html.twig")
64 1
     * @Method({"GET", "POST"})
65
     *
66
     * @return array
67
     */
68
    public function updatePasswordAction(Request $request, $token)
69
    {
70
        $user = $this->getDoctrine()->getRepository(User::class)->loadUserByToken($token);
71
        if ((!$user)) {
72
            return ['message' => 'Your link is expired!'];
73
        }
74 1
        $linkDate = $user->getLinkExpiredAt();
75
        $date = new \DateTime('now');
76
        if (($linkDate < $date)) {
77
            return ['message' => 'Your link is expired!'];
78
        }
79
        $form = $this->createForm(\AppBundle\Form\User\ResetPasswordType::class, $user);
80
        $form->handleRequest($request);
81
82
        if ($form->isSubmitted() && $form->isValid()) {
83
            $em = $this->getDoctrine()->getManager();
84
            $encoder = $this->get('security.password_encoder');
85
            $user->setPassword($encoder->encodePassword($user, $user->getPlainPassword()));
86
            $em->persist($user);
87
            $em->flush();
88
89
            return ['message' => 'Your password was successfully updated!', 'user' => $user];
90
        }
91
92
        return ['message' => 'Please, enter your new password', 'form' => $form->createView()];
93
    }
94
}
95