1 | <?php |
||
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) |
||
84 | |||
85 | /** |
||
86 | * Get Authentication-related Options |
||
87 | * |
||
88 | * @return AuthenticationOptionsInterface |
||
89 | */ |
||
90 | public function getAuthenticationOptions() |
||
94 | } |
||
95 |