LoginController::postLoginAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Egzaminer\Controller;
4
5
class LoginController extends AbstractController
6
{
7
    /**
8
     * Login page.
9
     *
10
     * GET /admin/login
11
     *
12
     * @return string
13
     */
14
    public function loginAction(): string
15
    {
16
        if ($this->isLogged()) {
17
            $this->redirect('/admin');
18
19
            $this->terminate();
20
        }
21
22
        return $this->render('front/login', ['title' => 'Logowanie']);
23
    }
24
25
    /**
26
     * Login post action.
27
     *
28
     * POST /admin/login
29
     *
30
     * @return void
31
     */
32
    public function postLoginAction()
33
    {
34
        if (true === $this->get('auth')->login(
35
                $this->getFromRequest('post', 'username'),
36
                $this->getFromRequest('post', 'password')
37
            )) {
38
            $this->setMessage('success', 'Zalogowano pomyślnie!');
39
            $this->redirect('/admin');
40
41
            $this->terminate();
42
        }
43
44
        $this->setMessage('warning', 'Złe hasło!');
45
        $this->redirect('/admin/login');
46
    }
47
}
48