line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::Form::PasswordChange; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12711282
|
use meon::Web::Util; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use HTML::FormHandler::Moose; |
6
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
7
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has '+name' => (default => 'form_password_change'); |
10
|
|
|
|
|
|
|
has '+widget_wrapper' => ( default => 'Bootstrap' ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has_field 'old_password' => ( |
13
|
|
|
|
|
|
|
type => 'Password', required => 0, label => 'Old Password', |
14
|
|
|
|
|
|
|
element_class => 'no-hide', |
15
|
|
|
|
|
|
|
element_attr => { placeholder => 'please enter your current password' } |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
has_field 'password' => ( |
18
|
|
|
|
|
|
|
type => 'Password', required => 0, label => 'New Password', |
19
|
|
|
|
|
|
|
element_class => 'no-hide', |
20
|
|
|
|
|
|
|
element_attr => { placeholder => 'please enter minimum 8 characters' } |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
has_field 'password_conf'=> ( |
23
|
|
|
|
|
|
|
type => 'Password', required => 0, label => 'Confirm Password Change', |
24
|
|
|
|
|
|
|
element_class => 'no-hide', |
25
|
|
|
|
|
|
|
element_attr => { placeholder => 'please retype your new password' } |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has_field 'submit' => ( type => 'Submit', value => 'Update', element_class => 'btn btn-primary', ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
before 'process' => sub { |
31
|
|
|
|
|
|
|
my $self = shift; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->field('old_password')->inactive(1) |
34
|
|
|
|
|
|
|
if $self->old_pw_not_required; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub old_pw_not_required { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
$self->c->session->{old_pw_not_required} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub validate { |
43
|
|
|
|
|
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $usr = $self->c->user; |
46
|
|
|
|
|
|
|
my $old_pw = $self->values->{old_password}; |
47
|
|
|
|
|
|
|
my $new_pw = $self->values->{password}; |
48
|
|
|
|
|
|
|
my $new_pw2 = $self->values->{password_conf}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return if (length($old_pw.$new_pw.$new_pw2) == 0); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
unless ($self->old_pw_not_required) { |
53
|
|
|
|
|
|
|
if (length($old_pw)) { |
54
|
|
|
|
|
|
|
$self->field('old_password')->add_error('Incorrect password') |
55
|
|
|
|
|
|
|
unless ($usr->check_password($old_pw)); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
|
|
|
|
|
|
$self->field('old_password')->add_error('Required'); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
if (length($new_pw)) { |
63
|
|
|
|
|
|
|
$self->field('password')->add_error('Password too short. Please enter at least 8 characters.') |
64
|
|
|
|
|
|
|
if (length($new_pw) < 8); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
|
|
|
|
|
|
$self->field('password')->add_error('Required'); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
if (length($new_pw2)) { |
71
|
|
|
|
|
|
|
$self->field('password_conf')->add_error('Confirmation password does not match') |
72
|
|
|
|
|
|
|
unless ($new_pw eq $new_pw2); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else { |
75
|
|
|
|
|
|
|
$self->field('password_conf')->add_error('Required'); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub submitted { |
80
|
|
|
|
|
|
|
my ($self) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $c = $self->c; |
83
|
|
|
|
|
|
|
my $xml = $c->model('ResponseXML')->dom; |
84
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
85
|
|
|
|
|
|
|
my $detach_path = $self->get_config_text('detach'); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return unless $self->is_valid; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
delete $c->session->{old_pw_not_required}; |
90
|
|
|
|
|
|
|
my $password = $self->field('password')->value; |
91
|
|
|
|
|
|
|
$c->user->set_password($password); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->detach($detach_path); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |