<?php

require ROOTDIR . "/includes/clientfunctions.php";

if($_POST['email']){
	$errormessage = doResetPWEmail($_POST['email'], '');	
}

if($_POST['key']&&$_POST['password1'] && $_POST['password2']){
	
	$invalidlink = doResetPWKeyCheck($_POST['key']);
	
	if(!$invalidlink && $_POST['password1']){
		
		if($_POST['password1'] == $_POST['password2']){
			
			$updatequery['password'] = md5(html_entity_decode($_POST['password1']));
		
			$errormessage = update_query("tblclients", $updatequery, array("pwresetkey" => $_POST['key']));				
		}else{
			$apiresults['error'] = 'The passwords entered do not match' ;	
		}
		
	}else{
		$apiresults['error'] = $invalidlink ;
	}	
}

$apiresults['status'] = $errormessage;
?>