#!/usr/local/bin/tclsh8.6

#
# Manage passwords
#
# Called by: pgaindex
#
# Parameters (form or url):
#   - display password modification page
#	- pw1, pw2 : (empty)
#   - process password modification
#	- pw1, pw2 : new password
#
# History
#   2003/07/29 : pda      : design
#   2003/06/27 : pda      : use cgi-exec
#   2007/12/04 : pda/jean : integration in netmagis
#   2010/12/29 : pda      : i18n and netmagis merge
#

#
# Template pages used by this script
#

set conf(page-choice)	pgapwd-choice.html
set conf(page-ok)	pgapwd-ok.html

#
# Next actions
#

set conf(next)		"pgapasswd"

#
# Netmagis general library
#

source /usr/local/lib/netmagis/libnetmagis.tcl

# ::webapp::cgidebug ; exit

##############################################################################
# Display password modification page
##############################################################################

d cgi-register {pw1 {}} {
} {
    global conf

    set minpwlen [::dnsconfig get "authpgminpwlen"]
    set maxpwlen [::dnsconfig get "authpgmaxpwlen"]

    d urlset "%URLFORM%" $conf(next)
    d result $conf(page-choice) [list \
					[list %MINPWLEN% $minpwlen] \
					[list %MAXPWLEN% $maxpwlen] \
				    ]
}

##############################################################################
# Process password modification
##############################################################################

d cgi-register {pw1 .+} {
    {pw2	1 1 }
} {
    global conf

    set c [list "change" $pw1 $pw2]
    set msg [pgauth-chpw $dbfd $tabuid(login) $c "nomail" {}]
    if {$msg ne ""} then {
	d error $msg
    }
    d result $conf(page-ok) [list \
				]
}


##############################################################################
# Main procedure
##############################################################################

d cgi-dispatch "dns" "pgauth"
