Completed
Push — master ( 50b1fc...ab1d0f )
by
unknown
11:33
created

LoginPresenter::actionOut()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
namespace FrontendModule;
4
5
use Nette\Application\UI;
6
use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
7
use Nette\Security as NS;
8
9
class LoginPresenter extends \FrontendModule\BasePresenter
10
{
11
    public function beforeRender()
12
    {
13
        parent::beforeRender();
14
15
        if ($this->getUser()->isLoggedIn()) {
16
            $this->forward('Homepage:');
17
        }
18
    }
19
20
    protected function startup()
21
    {
22
        parent::startup();
23
    }
24
25
    /**
26
     * Sign in form component factory.
27
     * @return UI\Form
28
     */
29
    protected function createComponentSignInForm($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        $form = new UI\Form();
32
33
        $form->getElementPrototype()->action = $this->link('default', array(
34
            'path' => 'loginfe',
35
            'abbr' => $this->abbr,
36
            'do' => 'signInForm-submit',
37
        ));
38
39
        $form->setRenderer(new BootstrapRenderer());
40
41
        $form->addText('username', 'Přihlašovací jméno')
42
            ->setRequired('Please provide a username.')
43
            ->setAttribute('placeholder', 'Přihlašovací jméno');
0 ignored issues
show
Documentation introduced by
'Přihlašovací jméno' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
45
        $form->addPassword('password', 'Heslo')
46
            ->setRequired('Please provide a password.')
47
            ->setAttribute('placeholder', 'Heslo');
0 ignored issues
show
Documentation introduced by
'Heslo' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
49
        $form->addCheckbox('remember', 'Permanent login?');
50
51
        $form->addSubmit('send', 'Přihlásit');
52
53
        $form->onSuccess[] = callback($this, 'signInFormSubmitted');
54
55
        return $form;
56
    }
57
58
    public function renderDefault()
59
    {
60
        $this->setLayout('login');
61
    }
62
63 View Code Duplication
    public function signInFormSubmitted($form)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
66
        try {
67
            $values = $form->getValues();
68
            if ($values->remember) {
69
                $this->getUser()->setExpiration('+ 14 days', false);
70
            } else {
71
                $this->getUser()->setExpiration('+ 20 minutes', true);
72
            }
73
            $this->getUser()->login($values->username, $values->password);
74
            $this->flashMessage('Přihlášení bylo úspěšné', 'success');
75
76
            //TODO bude upraveno - ted nestiham :)
77
            //$this->forward('Homepage:');
78
            $this->redirectUrl('http://test.webcook.cz/guaranteed-investment/www/pro-investory-1');
79
        } catch (NS\AuthenticationException $e) {
80
            $this->flashMessage($this->translation[$e->getMessage()], 'danger');
81
            $form->addError($e->getMessage());
82
        }
83
    }
84
85
    public function actionOut()
86
    {
87
        $this->getUser()->logout();
88
        $this->flashMessage('Odhlášení bylo úspěšné', 'success');
89
        $this->forward('Homepage:');
90
    }
91
92
}
93