<?php 
define('CURSCRIPT','register');

require_once './engine/common.inc.php';

if($action=='updatepwd'){
	$forget_mailcode=trim($forget_mailcode);
	$forget_uid=intval($forget_uid);
	$new_pwd=md5($new_pwd);
	if($forget_uid){
		if($db->query("delete FROM g_forgetpassword_mailcode WHERE emailcode='$forget_mailcode'")){
			$db->query("update g_members set userpwd = '$new_pwd' where uid=$forget_uid limit 1");
			showmsg("新密码设置成功,请使用新密码登录.","index.php");
		}
	}
}

if($action=='modifypwd'){
	$q=$db->query("SELECT uid FROM g_forgetpassword_mailcode WHERE emailcode='$mailcode'");
	$foregetuid=$db->result($q,0);
	if(!$foregetuid){
		showmsg("对不起,无效信息,请联系管理员","index.php");
	}
}
if($action=='getpwd'){
	if($authcode!=$forgetauthocode){
		showmsg('验证码输入不正确');
	}
	if(!$allowedemailmsg){
		showmsg('没有开启发送Email信息功能，请与管理员联系');
	}
	$reg_email=trim($reg_email);
	$q=$db->query("SELECT uid FROM g_members WHERE email='$reg_email'");
	if(!$db->num_rows($q)){
		showmsg("系统中不存在这个email地址");
	}
	$foregetuid=$db->result($q,0);
	$emailcode=md5(random(6));
    $db->query("replace into g_forgetpassword_mailcode (uid ,emailcode)VALUES ($foregetuid, '$emailcode')");
	$msg_title="你好，请点击链接修改账号密码";
	$msg_content=$sitename."提示:\n\r 你好,请点击链接修改账号密码\n\r ".cururldir()."forgetpassword.php?action=modifypwd&mailcode=".$emailcode;
	$msg_title=iconv("UTF-8","GB2312//IGNORE",$msg_title);
	$msg_content=iconv("UTF-8","GB2312//IGNORE",$msg_content);
	@gsendmail($reg_email,$msg_title,$msg_content);//此处有修改
	showmsg("密码修改信息已经发送至你的邮箱中","index.php",1);
}
require_once './clientdata/cache/cache_navigation.php';
include($templatedir."forgetpassword.tpl.php");
?>