Doc = &$Doc;
$this->User = SiteMap::getObj('User/User.php');
if (!$id = $this->User->checkAuthCode($auth)) skHTTP::redirect(Constant::get('BASE_URL'));
$form = $this->_getNewForm($auth);
if ($_REQUEST['action'] == '')
$form->exec();
switch ($_REQUEST['action']) {
case 'ch_pwd':
if (!$form->validate()) {
$form->exec();
break;
}
$user = array(
'password' => trim($_POST['pass']),
'auth' => '',
'id' => $id
);
$error=$this->User->changePassword($user);
skHTTP::redirect(Constant::get('BASE_URL').'/passwordchanged.html');
exit();
break;
default:
if ( $Doc->UserAuth->isLogged() ) {
skHTTP::redirect(Constant::get('BASE_URL').'/home');
exit();
}
break;
}
}
function _getNewForm($auth)
{
require_once 'class/Form/Form.class.php';
$form = new Form($this->Doc, 'change', 'post');
$UserData = $this->User->getUserByAuth($auth);
unset($UserData['password']);
$form->addElement('hidden', 'action', 'ch_pwd');
$form->addElement('hidden', 'auth', $auth);
$form->addElement('static', NULL, NULL, "Welcome back {$UserData['firstname']} {$UserData['lastname']} ({$UserData['login']})
");
$form->addElement('password', 'pass', 'Enter your new password', array('style'=> 'width:200px;'));
$form->addElement('password', 'pass2', 'Confirm your new password', array('style'=> 'width:200px;'));
$data = array();
$form->setDefaults($data);
$form->setCancelType(NULL);
$form->_requiredNote = NULL;
$form->submitTitle = 'Change';
$form->addRuleRequired(array('pass', 'pass2'));
$form->addFormRule(array(&$this, 'validForm'));
return $form;
}
function validForm($fields)
{
if ( trim($fields['pass']) != trim($fields['pass2']) ) {
return array('pass2' => 'Your password did not match!');
}
return true;
}
}
?>