<?php
class setpwdAction extends security_normal {
	
	function action(){
		$loginname=$this->_getParamId(1);
		$forgetpwd=$this->_getParamId(2);

		$miceSession = new session();

		global $conn;
		if($miceSession->get('mu__userid')){
			$user=new model_User();
			$user->setSubsection('WHERE loginname='.$miceSession->get('mu__loginname'));
			$results=$user->doSelectOne();

			$password1=$_POST['pwd1'];
			$password2=$_POST['pwd2'];
			$pwd='';
			if($password1==$password2 and strlen($password1)>4)
			{
				$salt = md5(rand(100000, 999999).$_POST['loginname']);
				$pwd=sha1($salt.$password1);
			}

			if($results)
			{
				if(strlen($pwd)>0){
					$user->setSalt($salt);
					$user->setPassword($pwd);
				}
				$user->setForgetpwd('');
				$results=$user->doUpdate();

				if($results)
					$exeresult='密码修改成功，请使用新密码登录网站';
				else
					$exeresult='验证错误，请联系网站管理员!';
			}else{
				$exeresult='验证错误，请联系网站管理员!';
			}
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"重设密码");';
			MessageBox($jsstring);
			exit;
		}elseif(strlen($loginname) AND strlen($forgetpwd)){
			$user=new model_User();
			$user->setSubsection("WHERE loginname='".strtolower($loginname)."' AND forgetpwd='".$forgetpwd."'");
			$results=$user->doSelectOne();

			if(!$results){
				$jsstring='Dialog.alert(\'验证错误，请联系网站管理员!\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"重设密码");';
				MessageBox($jsstring);
				exit;
			}
		}else{
			$jsstring='Dialog.alert(\'验证错误，请联系网站管理员!\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"重设密码");';
			MessageBox($jsstring);
			exit;
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign("name",$name);
		$smarty->assign("results",$results);
		$smarty->assign("checkcode",MICE_URL.'index.php/checkcode');

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>