%doc>
Self-service person maintenance for regular users
%doc>
%
%
<%attr>
title => 'Person'
%attr>
%
%
<%args>
$id
$user => $ui->get_current_user($r)
$edit => undef
$submit => undef
$chpass => undef
$oldpass => undef
$newpass1 => undef
$newpass2 => undef
%args>
%
%
<%init>
my $DEBUG = 0;
print "
", Dumper(%ARGS), "
" if $DEBUG;
my $o = Person->retrieve($id);
my %exclude = (
'username' => 1,
'password' => 1,
'user_type' => 1,
'info' => 1,
);
# This controls whether we offer the password change option
my $can_passwd = $ui->config->get('USER_CAN_CHANGE_PASSWORD');
%init>
<%perl>
if ( $submit ){
if ( $submit eq "Update" ){
my %columns;
map { $columns{$_} = 1 } Person->meta_data->get_column_names;
my %uargs; # Update args
foreach my $c ( keys %ARGS ){
next if $c eq 'id';
next unless $columns{$c};
next if $exclude{$c};
$uargs{$c} = $ARGS{$c};
}
eval {
Netdot::Model->do_transaction( sub{
$o->update(\%uargs);
});
};
if ( my $e = $@ ){
$m->comp('../generic/error.mhtml', error=>$e);
}
}elsif ( $can_passwd && $submit eq 'Change' ){
unless ( $oldpass && $newpass1 && $newpass2 ){
$m->comp('../generic/error.mhtml', error=>"You are missing one or more fields");
}
unless ( $o->verify_passwd($oldpass) ){
$m->comp('../generic/error.mhtml', error=>"Your old password does not match what's in the DB");
}
unless ( $newpass1 eq $newpass2 ){
$m->comp('../generic/error.mhtml', error=>"Your new passwords don't match");
}
# The Person class will take care of encrypting it
eval {
$o->update({password=>$newpass1});
};
if ( my $e = $@ ){
$m->comp('../generic/error.mhtml', error=>$e);
}else{
$m->comp('.show_message', title=>"Action Message", msg=>"Password updated successfully");
}
}
}
%perl>
<%def .show_message>
<%args>
$title => undef
$msg => undef
%args>
%def>