<h3>Changing Password for user <%$user|h%></h3>
<& SELF:error &>
% unless (defined $cmd and $cmd eq 'change'){
    <& SELF:change &>
% }
<%args>
$pw1 => undef
$pw2 => undef
$cmd => undef
</%args>
<%shared>
my $user   = $m->session->{user};
my $userip = $r->connection->remote_ip; 
my $secure = &is_secure;
my $err    = '';
</%shared>
<%init>
# Send to https if not secure.
unless ($secure){
    my $url = url_secure($r->uri);
    $m->redirect($url);
}

unless ($user){
    $err = "Who are you?";
    $cmd = undef;
}

unless ($m->session->{useuserdb}) {
    $err = "You can't change your apache password this way.";
    $cmd = undef;
}

if ($cmd eq 'change'){
    unless ($pw1 eq $pw2){
        $err = "Passwords do not match.<BR>";
    }

    unless ($err){
        my $rv = netdisco::user_add($user,('pw' => $pw1));
        $err .= $rv ? "Could not Change Password! $rv<BR>\n" : "Password for $user changed.<BR>\n";

        # Log Change Password
        insert_or_update('user_log',{},
                {'username'=>$user,'event'=>'pw_change',
                 'userip'=>$userip,'details' => $rv ? 'Failed' : 'Succeeded'});
    }
    undef $cmd;
}
</%init>
<%method change>
<FORM ACTION="<%$r->uri%>" METHOD=POST>
<INPUT TYPE="hidden" NAME="cmd" VALUE="change">
<TABLE>
<TR>
    <TD>Enter New Password :</TD>
    <TD><INPUT TYPE="PASSWORD" NAME="pw1" SIZE=10 MAXLENGTH=30></TD>
</TR>
<TR>
    <TD>Enter Password Again:</TD>
    <TD><INPUT TYPE="PASSWORD" NAME="pw2" SIZE=10 MAXLENGTH=30></TD>
</TR>
</TABLE>
<INPUT TYPE="SUBMIT" VALUE="Change Password for <%$user|h%>">
</FORM>
</%method>
<%method error>
% return unless $err;
<h3><%$err%></h3>
</%method>
<%method title>
- Change Password \
</%method>
%# $Id: change_pw.html,v 1.4 2006/03/09 00:05:36 fenner Exp $
%# vim:syntax=mason
