Completed
Pull Request — master (#30)
by nonanerz
05:26
created

DefaultController::indexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\Request;
10
use AppBundle\Entity\User;
11
12
class DefaultController extends Controller
13
{
14
    /**
15
     * @Route("/", name="homepage")
16
     * @Template("@App/dashboard.html.twig")
17
     */
18
    public function indexAction()
19
    {
20
        return [];
21
    }
22
23
    /**
24
     * @Route("/login", name="login")
25
     *
26
     * @return array
27
     * @Method({"GET", "POST"})
28
     * @Template("@App/login.html.twig")
29
     */
30 6
    public function loginAction()
31
    {
32 6
        $authenticationUtils = $this->get('security.authentication_utils');
33 6
        $error = $authenticationUtils->getLastAuthenticationError();
34 6
        $lastUsername = $authenticationUtils->getLastUsername();
35
36
        return [
37 6
            'last_username' => $lastUsername, //$lastUsername,
38 6
            'error' => $error,
39
        ];
40
    }
41
42
    /**
43
     * @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...
44
     * @Route("/password_update/{token}", name="password_update")
45
     * @Template("@App/User/update_password.html.twig")
46
     * @Method({"GET", "POST"})
47
     *
48
     * @return array
49
     */
50 1
    public function updatePasswordAction(Request $request, $token)
51
    {
52 1
        $user = $this->getDoctrine()->getRepository(User::class)->loadUserByToken($token);
53 1
        if ((!$user)) {
54
            return ['message' => 'Your link is expired!'];
55
        }
56 1
        $linkDate = $user->getLinkExpiredAt();
57 1
        $date = new \DateTime('now');
58 1
        if (($linkDate < $date)) {
59
            return ['message' => 'Your link is expired!'];
60
        }
61 1
        $form = $this->createForm(\AppBundle\Form\User\ResetPasswordType::class, $user);
62 1
        $form->handleRequest($request);
63
64 1
        if ($form->isSubmitted() && $form->isValid()) {
65
            $em = $this->getDoctrine()->getManager();
66
            $encoder = $this->get('security.password_encoder');
67
            $user->setPassword($encoder->encodePassword($user, $user->getPlainPassword()));
68
            $em->persist($user);
69
            $em->flush();
70
71
            return ['message' => 'Your password was successfully updated!', 'user' => $user];
72
        }
73
74 1
        return ['message' => 'Please, enter your new password', 'form' => $form->createView()];
75
    }
76
}
77