Login   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 86
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setAuthenticationOptions() 0 5 1
A getAuthenticationOptions() 0 4 1
A __construct() 0 56 3
1
<?php
2
3
namespace ZfcUser\Form;
4
5
use Zend\Form\Element;
6
use ZfcBase\Form\ProvidesEventsForm;
7
use ZfcUser\Options\AuthenticationOptionsInterface;
8
9
class Login extends ProvidesEventsForm
10
{
11
    /**
12
     * @var AuthenticationOptionsInterface
13
     */
14
    protected $authOptions;
15
16
    public function __construct($name, AuthenticationOptionsInterface $options)
17
    {
18
        $this->setAuthenticationOptions($options);
19
        parent::__construct($name);
20
21
        $this->add(array(
22
            'name' => 'identity',
23
            'options' => array(
24
                'label' => '',
25
            ),
26
            'attributes' => array(
27
                'type' => 'text'
28
            ),
29
        ));
30
31
        $emailElement = $this->get('identity');
32
        $label = $emailElement->getLabel('label');
33
        // @TODO: make translation-friendly
34
        foreach ($this->getAuthenticationOptions()->getAuthIdentityFields() as $mode) {
35
            $label = (!empty($label) ? $label . ' or ' : '') . ucfirst($mode);
36
        }
37
        $emailElement->setLabel($label);
38
        //
39
        $this->add(array(
40
            'name' => 'credential',
41
            'type' => 'password',
42
            'options' => array(
43
                'label' => 'Password',
44
            ),
45
            'attributes' => array(
46
                'type' => 'password',
47
            ),
48
        ));
49
50
        // @todo: Fix this
51
        // 1) getValidator() is a protected method
52
        // 2) i don't believe the login form is actually being validated by the login action
53
        // (but keep in mind we don't want to show invalid username vs invalid password or
54
        // anything like that, it should just say "login failed" without any additional info)
55
        //$csrf = new Element\Csrf('csrf');
56
        //$csrf->getValidator()->setTimeout($options->getLoginFormTimeout());
57
        //$this->add($csrf);
58
59
        $submitElement = new Element\Button('submit');
60
        $submitElement
61
            ->setLabel('Sign In')
62
            ->setAttributes(array(
63
                'type'  => 'submit',
64
            ));
65
66
        $this->add($submitElement, array(
67
            'priority' => -100,
68
        ));
69
70
        $this->getEventManager()->trigger('init', $this);
71
    }
72
73
    /**
74
     * Set Authentication-related Options
75
     *
76
     * @param AuthenticationOptionsInterface $authOptions
77
     * @return Login
78
     */
79
    public function setAuthenticationOptions(AuthenticationOptionsInterface $authOptions)
80
    {
81
        $this->authOptions = $authOptions;
82
        return $this;
83
    }
84
85
    /**
86
     * Get Authentication-related Options
87
     *
88
     * @return AuthenticationOptionsInterface
89
     */
90
    public function getAuthenticationOptions()
91
    {
92
        return $this->authOptions;
93
    }
94
}
95