<?php
	if (Tourists()){ header('refresh:0;url=./index.php?act=my'); exit; }

	if (!empty ($_GET['type'])){
		if ((!empty ($_GET['user']) || !empty ($_POST['user'])) && (!empty ($_POST['email']) || !empty ($_GET['key']))){
			$user = !empty ($_GET['user']) ? $_GET['user'] : $_POST['user'];

			if ($_GET['type'] == 'reset' and !empty ($_GET['key'])){   #重置
				if (!empty ($_POST['pass'])){
					$pass = $_POST['pass'];
					$data = mysql_fetch_array (mysql_query ("SELECT * FROM `user` WHERE `user`='$user'"));
					if ($_GET['key'] == create_yzm ($data['pass'])){
						if (strlen ($pass) < 3 or strlen ($pass) > 15){
							$info = '<p>新密码位数必须在3位至15位之间！</p><p><a href="index.php?act=password_get">点此返回>></a></p>';
						}else if (!@eReg ('^[0-9a-zA-Z\_]*$',$pass)){
							$info = '<p>新密码必须为数字或英文字符！</p><p><a href="index.php?act=password_get">点此返回>></a></p>';
						}else{
							$ip = ip();
							$date = date('Y-m-d H:i:s');
							mysql_query ("UPDATE `user` SET `pass`='$pass' WHERE `user`='$user'");
							Send_out_Mail ($data['email'],"[{$configure[webname]}]密码重置成功","尊敬的 {$user} 用户，您的密码于 {$date} 成功重置！<br><br>您的新密码为：{$pass}<br><br><br>执行人IP地址：{$ip}<br><br><br>若非您本人操作，请及时锁定账号并告知我们，我们将会对此IP地址进行全面封杀！<br><br><br><br>感谢您对我们的大力支持！祝您使用愉快，再见！");
							$info = '<p>恭喜您，密码重置成功！</p><p><a href="index.php?act=password_get">点此返回>></a></p>';
						}
					}else{
						$info = '<p>重置连接已失效！</p><p><a href="index.php?act=password_get">点此返回>></a></p>';
					}
				}else{
					$info = 'Case 2'; //载入密码页面
				}
			}else if ($_GET['type'] == 'Verify' and !empty ($_POST['email'])){   #验证
				$data = mysql_fetch_array (mysql_query ("SELECT * FROM `user` WHERE `user`='$user'"));
				if ($data['email'] != Null and $data['email'] == $_POST['email']){
					$ip = ip();
					$url = $WebSite_Url.'index.php?act=password_get&type=reset&user='.$user.'&key='.create_yzm ($data['pass']);
					Send_out_Mail ($_POST['email'],"[{$configure[webname]}]密码重置验证","亲爱的 $user ，您好！<br><br><br>您的密码重置连接为：$url<br><br>请您尽快使用，防止被他人利用<br><br>执行人IP地址：$ip<br><br>若非您本人操作请忽略此邮件！");
					$info = '<p>密码找回邮件已成功发送至您的邮箱，请查收！</p>';
				}else{
					$info = '<p>邮箱验证失败，无法进行下一步！</p><p><a href="index.php?act=password_get">点此返回>></a></p>';
				}
			}
		}else{
			$info = '<p>账号或邮箱不能为空！</p><p><a href="index.php?act=password_get">点此返回>></a></p>';
		}
	}else{
		$info = 'Case 1'; //载入重置页面
	}

	$AnYue_Smarty -> assign ('info',$info);
	$AnYue_Smarty -> display ('password_get.html');