| 1 | package Tags::HTML::Login::Access; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use base qw(Tags::HTML); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 5 | ▶ | use Class::Utils qw(set_params split_params); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Error::Pure qw(err); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use List::Util 1.33 qw(none); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use Mo::utils::Array qw(check_array); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 5 | ▶ | use Mo::utils::CSS 0.07 qw(check_css_unit); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 5 | ▶ | use Mo::utils::Language 0.05 qw(check_language_639_2); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 5 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 5 | ▶ | use Tags::HTML::Messages; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 5 | Readonly::Array our @FORM_METHODS => qw(post get); | |||||||||
| 17 | |||||||||||
| 18 | 5 | our $VERSION = 0.14; | |||||||||
| 19 | |||||||||||
| 20 | # Constructor. | ||||||||||
| 21 | 29 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 22 | 29 | my ($class, @params) = @_; | |||||||||
| 23 | |||||||||||
| 24 | # Create object. | ||||||||||
| 25 | 29 | my ($object_params_ar, $other_params_ar) = split_params( | |||||||||
| 26 | ['css_access', 'form_method', 'lang', 'logo_image_url', 'register_url', | ||||||||||
| 27 | 'tags_after', 'text', 'width'], @params); | ||||||||||
| 28 | 29 | my $self = $class->SUPER::new(@{$other_params_ar}); | |||||||||
| 29 | |||||||||||
| 30 | # CSS style for access box. | ||||||||||
| 31 | 26 | $self->{'css_access'} = 'form-login'; | |||||||||
| 32 | |||||||||||
| 33 | # Form method. | ||||||||||
| 34 | 26 | $self->{'form_method'} = 'post'; | |||||||||
| 35 | |||||||||||
| 36 | # Language. | ||||||||||
| 37 | 26 | $self->{'lang'} = 'eng'; | |||||||||
| 38 | |||||||||||
| 39 | # Logo. | ||||||||||
| 40 | 26 | $self->{'logo_image_url'} = undef; | |||||||||
| 41 | |||||||||||
| 42 | # Register URL. | ||||||||||
| 43 | 26 | $self->{'register_url'} = undef; | |||||||||
| 44 | |||||||||||
| 45 | # Tags code after form. | ||||||||||
| 46 | 26 | $self->{'tags_after'} = []; | |||||||||
| 47 | |||||||||||
| 48 | # Language texts. | ||||||||||
| 49 | 26 | $self->{'text'} = { | |||||||||
| 50 | 'eng' => { | ||||||||||
| 51 | 'login' => 'Login', | ||||||||||
| 52 | 'password_label' => 'Password', | ||||||||||
| 53 | 'username_label' => 'User name', | ||||||||||
| 54 | 'submit' => 'Login', | ||||||||||
| 55 | 'register' => 'Register', | ||||||||||
| 56 | }, | ||||||||||
| 57 | }; | ||||||||||
| 58 | |||||||||||
| 59 | # Login box width. | ||||||||||
| 60 | 26 | $self->{'width'} = '300px'; | |||||||||
| 61 | |||||||||||
| 62 | # Process params. | ||||||||||
| 63 | 26 | set_params($self, @{$object_params_ar}); | |||||||||
| 64 | |||||||||||
| 65 | # Check form method. | ||||||||||
| 66 | 26 | ▶ | if (none { $self->{'form_method'} eq $_ } @FORM_METHODS) { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 67 | 1 | err "Parameter 'form_method' has bad value."; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | # Check lang. | ||||||||||
| 71 | 25 | check_language_639_2($self, 'lang'); | |||||||||
| 72 | |||||||||||
| 73 | # Check text for lang | ||||||||||
| 74 | 24 | ▶ | if (! defined $self->{'text'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 1 | err "Parameter 'text' is required."; | |||||||||
| 76 | } | ||||||||||
| 77 | 23 | ▶ | if (ref $self->{'text'} ne 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 1 | err "Parameter 'text' must be a hash with language texts."; | |||||||||
| 79 | } | ||||||||||
| 80 | 22 | ▶ | if (! exists $self->{'text'}->{$self->{'lang'}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 1 | err "Texts for language '$self->{'lang'}' doesn't exist."; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 21 | check_array($self, 'tags_after'); | |||||||||
| 85 | |||||||||||
| 86 | 20 | check_css_unit($self, 'width'); | |||||||||
| 87 | |||||||||||
| 88 | $self->{'_tags_messages'} = Tags::HTML::Messages->new( | ||||||||||
| 89 | 'css' => $self->{'css'}, | ||||||||||
| 90 | 'flag_no_messages' => 0, | ||||||||||
| 91 | 17 | 'tags' => $self->{'tags'}, | |||||||||
| 92 | ); | ||||||||||
| 93 | |||||||||||
| 94 | # Object. | ||||||||||
| 95 | 17 | return $self; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | # Process 'Tags'. | ||||||||||
| 99 | 10 | ▶ | sub _process { | ||||||||
|
Subroutine
_process: called CC=3 SCAR=11.0
| |||||||||||
| 100 | 10 | my ($self, $messages_ar) = @_; | |||||||||
| 101 | |||||||||||
| 102 | 10 | my $username_id = 'username'; | |||||||||
| 103 | 10 | my $password_id = 'password'; | |||||||||
| 104 | |||||||||||
| 105 | $self->{'tags'}->put( | ||||||||||
| 106 | ['b', 'form'], | ||||||||||
| 107 | ['a', 'class', $self->{'css_access'}], | ||||||||||
| 108 | 10 | ['a', 'method', $self->{'form_method'}], | |||||||||
| 109 | |||||||||||
| 110 | ['b', 'fieldset'], | ||||||||||
| 111 | ['b', 'legend'], | ||||||||||
| 112 | ['d', $self->_text('login')], | ||||||||||
| 113 | ['e', 'legend'], | ||||||||||
| 114 | ); | ||||||||||
| 115 | |||||||||||
| 116 | 9 | ▶ | if (defined $self->{'logo_image_url'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | $self->{'tags'}->put( | ||||||||||
| 118 | ['b', 'div'], | ||||||||||
| 119 | ['a', 'class', 'logo'], | ||||||||||
| 120 | ['b', 'img'], | ||||||||||
| 121 | 1 | ['a', 'src', $self->{'logo_image_url'}], | |||||||||
| 122 | ['a', 'alt', 'logo'], | ||||||||||
| 123 | ['e', 'img'], | ||||||||||
| 124 | ['e', 'div'], | ||||||||||
| 125 | ); | ||||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | $self->{'tags'}->put( | ||||||||||
| 129 | |||||||||||
| 130 | ['b', 'p'], | ||||||||||
| 131 | ['b', 'label'], | ||||||||||
| 132 | ['a', 'for', $username_id], | ||||||||||
| 133 | ['d', $self->_text('username_label')], | ||||||||||
| 134 | ['e', 'label'], | ||||||||||
| 135 | ['b', 'input'], | ||||||||||
| 136 | ['a', 'type', 'text'], | ||||||||||
| 137 | ['a', 'name', $username_id], | ||||||||||
| 138 | ['a', 'id', $username_id], | ||||||||||
| 139 | ['a', 'autofocus', 'autofocus'], | ||||||||||
| 140 | ['e', 'input'], | ||||||||||
| 141 | ['e', 'p'], | ||||||||||
| 142 | |||||||||||
| 143 | ['b', 'p'], | ||||||||||
| 144 | ['b', 'label'], | ||||||||||
| 145 | ['a', 'for', $password_id], | ||||||||||
| 146 | ['d', $self->_text('password_label')], | ||||||||||
| 147 | ['e', 'label'], | ||||||||||
| 148 | ['b', 'input'], | ||||||||||
| 149 | ['a', 'type', 'password'], | ||||||||||
| 150 | ['a', 'name', $password_id], | ||||||||||
| 151 | ['a', 'id', $password_id], | ||||||||||
| 152 | ['e', 'input'], | ||||||||||
| 153 | ['e', 'p'], | ||||||||||
| 154 | |||||||||||
| 155 | ['b', 'p'], | ||||||||||
| 156 | ['b', 'button'], | ||||||||||
| 157 | ['a', 'type', 'submit'], | ||||||||||
| 158 | ['a', 'name', 'login'], | ||||||||||
| 159 | ['a', 'value', 'login'], | ||||||||||
| 160 | ['d', $self->_text('submit')], | ||||||||||
| 161 | ['e', 'button'], | ||||||||||
| 162 | ['e', 'p'], | ||||||||||
| 163 | |||||||||||
| 164 | defined $self->{'register_url'} ? ( | ||||||||||
| 165 | ['b', 'a'], | ||||||||||
| 166 | ['a', 'href', $self->{'register_url'}], | ||||||||||
| 167 | ['d', $self->_text('register')], | ||||||||||
| 168 | ['e', 'a'], | ||||||||||
| 169 | ) : (), | ||||||||||
| 170 | |||||||||||
| 171 | 9 | ▶ | @{$self->{'tags_after'}}, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 172 | |||||||||||
| 173 | ['e', 'fieldset'], | ||||||||||
| 174 | ); | ||||||||||
| 175 | |||||||||||
| 176 | 9 | $self->{'_tags_messages'}->process($messages_ar); | |||||||||
| 177 | |||||||||||
| 178 | 6 | $self->{'tags'}->put( | |||||||||
| 179 | ['e', 'form'], | ||||||||||
| 180 | ); | ||||||||||
| 181 | |||||||||||
| 182 | 6 | return; | |||||||||
| 183 | } | ||||||||||
| 184 | |||||||||||
| 185 | # Process 'CSS::Struct'. | ||||||||||
| 186 | 3 | ▶ | sub _process_css { | ||||||||
|
Subroutine
_process_css: called CC=1 SCAR=0.0
| |||||||||||
| 187 | 3 | my ($self, $message_types_hr) = @_; | |||||||||
| 188 | |||||||||||
| 189 | $self->{'css'}->put( | ||||||||||
| 190 | ['s', '.'.$self->{'css_access'}], | ||||||||||
| 191 | ['d', 'width', $self->{'width'}], | ||||||||||
| 192 | ['d', 'background-color', '#f2f2f2'], | ||||||||||
| 193 | ['d', 'padding', '20px'], | ||||||||||
| 194 | ['d', 'border-radius', '5px'], | ||||||||||
| 195 | ['d', 'box-shadow', '0 0 10px rgba(0, 0, 0, 0.2)'], | ||||||||||
| 196 | ['e'], | ||||||||||
| 197 | |||||||||||
| 198 | ['s', '.'.$self->{'css_access'}.' .logo'], | ||||||||||
| 199 | ['d', 'height', '5em'], | ||||||||||
| 200 | ['d', 'width', '100%'], | ||||||||||
| 201 | ['e'], | ||||||||||
| 202 | |||||||||||
| 203 | ['s', '.'.$self->{'css_access'}.' img'], | ||||||||||
| 204 | ['d', 'margin', 'auto'], | ||||||||||
| 205 | ['d', 'display', 'block'], | ||||||||||
| 206 | ['d', 'max-width', '100%'], | ||||||||||
| 207 | ['d', 'max-height', '5em'], | ||||||||||
| 208 | ['e'], | ||||||||||
| 209 | |||||||||||
| 210 | ['s', '.'.$self->{'css_access'}.' fieldset'], | ||||||||||
| 211 | ['d', 'border', 'none'], | ||||||||||
| 212 | ['d', 'padding', 0], | ||||||||||
| 213 | ['d', 'margin-bottom', '20px'], | ||||||||||
| 214 | ['e'], | ||||||||||
| 215 | |||||||||||
| 216 | ['s', '.'.$self->{'css_access'}.' legend'], | ||||||||||
| 217 | ['d', 'font-weight', 'bold'], | ||||||||||
| 218 | ['d', 'margin-bottom', '10px'], | ||||||||||
| 219 | ['e'], | ||||||||||
| 220 | |||||||||||
| 221 | ['s', '.'.$self->{'css_access'}.' p'], | ||||||||||
| 222 | ['d', 'margin', 0], | ||||||||||
| 223 | ['d', 'padding', '10px 0'], | ||||||||||
| 224 | ['e'], | ||||||||||
| 225 | |||||||||||
| 226 | ['s', '.'.$self->{'css_access'}.' label'], | ||||||||||
| 227 | ['d', 'display', 'block'], | ||||||||||
| 228 | ['d', 'font-weight', 'bold'], | ||||||||||
| 229 | ['d', 'margin-bottom', '5px'], | ||||||||||
| 230 | ['e'], | ||||||||||
| 231 | |||||||||||
| 232 | ['s', '.'.$self->{'css_access'}.' input[type="text"]'], | ||||||||||
| 233 | ['s', '.'.$self->{'css_access'}.' input[type="password"]'], | ||||||||||
| 234 | ['d', 'width', '100%'], | ||||||||||
| 235 | ['d', 'padding', '8px'], | ||||||||||
| 236 | ['d', 'border', '1px solid #ccc'], | ||||||||||
| 237 | ['d', 'border-radius', '3px'], | ||||||||||
| 238 | ['e'], | ||||||||||
| 239 | |||||||||||
| 240 | ['s', '.'.$self->{'css_access'}.' button[type="submit"]'], | ||||||||||
| 241 | ['d', 'width', '100%'], | ||||||||||
| 242 | ['d', 'padding', '10px'], | ||||||||||
| 243 | ['d', 'background-color', '#4CAF50'], | ||||||||||
| 244 | ['d', 'color', '#fff'], | ||||||||||
| 245 | ['d', 'border', 'none'], | ||||||||||
| 246 | ['d', 'border-radius', '3px'], | ||||||||||
| 247 | ['d', 'cursor', 'pointer'], | ||||||||||
| 248 | ['e'], | ||||||||||
| 249 | |||||||||||
| 250 | ['s', '.'.$self->{'css_access'}.' button[type="submit"]:hover'], | ||||||||||
| 251 | ['d', 'background-color', '#45a049'], | ||||||||||
| 252 | ['e'], | ||||||||||
| 253 | |||||||||||
| 254 | 3 | ['s', '.'.$self->{'css_access'}.' .messages'], | |||||||||
| 255 | ['d', 'text-align', 'center'], | ||||||||||
| 256 | ['e'], | ||||||||||
| 257 | ); | ||||||||||
| 258 | |||||||||||
| 259 | 3 | $self->{'_tags_messages'}->process_css($message_types_hr); | |||||||||
| 260 | |||||||||||
| 261 | 2 | return; | |||||||||
| 262 | } | ||||||||||
| 263 | |||||||||||
| 264 | 38 | ▶ | sub _text { | ||||||||
|
Subroutine
_text: called CC=2 SCAR=6.9
| |||||||||||
| 265 | 38 | my ($self, $key) = @_; | |||||||||
| 266 | |||||||||||
| 267 | 38 | ▶ | if (! exists $self->{'text'}->{$self->{'lang'}}->{$key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 268 | 1 | err "Text for lang '$self->{'lang'}' and key '$key' doesn't exist."; | |||||||||
| 269 | } | ||||||||||
| 270 | |||||||||||
| 271 | 37 | return $self->{'text'}->{$self->{'lang'}}->{$key}; | |||||||||
| 272 | } | ||||||||||
| 273 | |||||||||||
| 274 | 5 | 1; | |||||||||
| 275 | |||||||||||
| 276 | __END__ | ||||||||||