1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Users;
13
14 use ICanBoogie\I18n;
15 use ICanBoogie\Operation;
16
17 use Brickrouge;
18 use Brickrouge\A;
19 use Brickrouge\Button;
20 use Brickrouge\Element;
21 use Brickrouge\Form;
22 use Brickrouge\Text;
23
24 class LoginForm extends Form
25 {
26 const PASSWORD_RECOVERY_LINK = '#password-recovery-link';
27
28 public $lost_password = [];
29
30 31 32 33 34
35 static protected function add_assets(\Brickrouge\Document $document)
36 {
37 $document->css->add(DIR . 'public/widget.css');
38 $document->js->add(DIR . 'public/widget.js');
39
40 parent::add_assets($document);
41 }
42
43 public function __construct(array $attributes=[])
44 {
45 global $core;
46
47 $this->lost_password = new A(I18n\t('lost_password', [], [ 'scope' => 'users.label', 'default' => 'I forgot my password' ]), "#lost-password", [
48
49 'rel' => 'nonce-request'
50
51 ]);
52
53 parent::__construct($attributes + [
54
55 Form::ACTIONS => [
56
57 new Button('Connect', [
58
59 'type' => 'submit',
60 'class' => 'btn-primary'
61
62 ])
63
64 ],
65
66 Form::RENDERER => 'Simple',
67
68 Form::HIDDENS => [
69
70 Operation::DESTINATION => 'users',
71 Operation::NAME => Module::OPERATION_LOGIN,
72 Operation::SESSION_TOKEN => $core->session->token,
73 'redirect_to' => $core->request['redirect_to']
74
75 ],
76
77 Element::CHILDREN => [
78
79 User::USERNAME => new Text([
80
81 Form::LABEL => 'username',
82 Element::REQUIRED => true,
83
84 'autofocus' => true
85
86 ]),
87
88 User::PASSWORD => new Text([
89
90 Form::LABEL => 'password',
91 Element::REQUIRED => true,
92 Element::DESCRIPTION => $this->lost_password,
93
94 'type' => 'password'
95
96 ])
97 ],
98
99 Element::WIDGET_CONSTRUCTOR => 'Login',
100
101 'class' => 'widget-login',
102 'name' => 'users/login'
103
104 ]);
105 }
106
107 public function render()
108 {
109 $password_recovery_link = $this[self::PASSWORD_RECOVERY_LINK];
110
111 if ($password_recovery_link)
112 {
113 $this->lost_password['href'] = $password_recovery_link;
114 }
115
116 return parent::render();
117 }
118 }