<h1 class="pagehead">Changing Password for user <%$user|h%></h1>
<& 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->client_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>
<DIV>
<INPUT TYPE="hidden" NAME="cmd" VALUE="change">
<TABLE CLASS="adm-search">
<TR>
    <TH>Enter New Password:</TH>
    <TD><INPUT TYPE="PASSWORD" NAME="pw1" SIZE=10 MAXLENGTH=30></TD>
</TR>
<TR>
    <TH>Enter Password Again:</TH>
    <TD><INPUT TYPE="PASSWORD" NAME="pw2" SIZE=10 MAXLENGTH=30></TD>
</TR>
<TR>
    <TH>&nbsp;</TH>
    <TD><INPUT TYPE="submit" CLASS="navbutton" VALUE="Change Password for <%$user|h%>"></TD>
</TR>
</TABLE>
</DIV>
</FORM>
</%method>
<%method error>
% return unless $err;
<h1 class="pagehead"><%$err%></h1>
</%method>
<%method title>
- Change Password \
</%method>
%# $Id$
%# vim:syntax=mason
