Debian Codegraph @

lib/HTML/FormHandler/Field/PasswordConf.pm

raw
1 package HTML::FormHandler::Field::PasswordConf;
2 # ABSTRACT: password confirmation
3 $HTML::FormHandler::Field::PasswordConf::VERSION = '0.410002';
4 use HTML::FormHandler::Moose;
5 extends 'HTML::FormHandler::Field::Text';
6
7
8 has '+widget' => ( default => 'Password' );
9 has '+password' => ( default => 1 );
10 has '+required' => ( default => 1 );
11 has 'password_field' => ( isa => 'Str', is => 'rw', default => 'password' );
12 has 'pass_conf_message' => ( isa => 'Str', is => 'rw' );
13
14 our $class_messages = {
15 required => 'Please enter a password confirmation',
16 pass_conf_not_matched => 'The password confirmation does not match the password',
17 };
18
19 sub get_class_messages {
20 my $self = shift;
21 my $messages = {
22 %{ $self->next::method },
23 %$class_messages,
24 };
25 $messages->{pass_conf_not_matched} = $self->pass_conf_message
26 if $self->pass_conf_message;
27 return $messages;
28 }
29
30
31 sub validate {
32 my $self = shift;
33
34 my $value = $self->value;
35 my $password = $self->form->field( $self->password_field )->value || '';
36 if ( $password ne $self->value ) {
37 $self->add_error( $self->get_message('pass_conf_not_matched') );
38 return;
39 }
40 return 1;
41 }
42
43 __PACKAGE__->meta->make_immutable;
44 use namespace::autoclean;
45 1;
46
47 __END__
48
49 =pod
50
51 =encoding UTF-8
52
53 =head1 NAME
54
55 HTML::FormHandler::Field::PasswordConf - password confirmation
56
57 =head1 VERSION
58
59 version 0.410002
60
61 =head1 DESCRIPTION
62
63 This field needs to be declared after the related Password field (or more
64 precisely it needs to come after the Password field in the list returned by
65 the L<HTML::FormHandler/fields> method).
66
67 =head2 password_field
68
69 Set this attribute to the name of your password field (default 'password')
70
71 Customize error message 'pass_conf_not_matched' or 'required'
72
73 has_field '_password' => ( type => 'PasswordConf',
74 messages => { required => 'You must enter the password a second time' },
75 );
76
77 =head1 AUTHOR
78
79 FormHandler Contributors - see HTML::FormHandler
80
81 =head1 COPYRIGHT AND LICENSE
82
83 This software is copyright (c) 2017 by Gerda Shank.
84
85 This is free software; you can redistribute it and/or modify it under
86 the same terms as the Perl 5 programming language system itself.
87
88 =cut