<?php
include_once 'tgydapicommon.php';
include_once 'cons.php';
$m_host=C('mail_host');
$m_user = C('mail_email');
$m_pwd = C('mail_pwd');
$m_port = C('mail_port');
$p_url = $_SERVER['SERVER_NAME'];
if($_GET['type']=='findpwd'){
	session_start();
	$_code = $_SESSION['klsf_code'];
	$code = $_POST['code'];
	$email = $_POST['email'];
	$name = $_POST['name'];
	if(!preg_match('/^[A-z0-9._-]+@[A-z0-9._-]+\.[A-z0-9._-]+$/', $email)){
		exit("<script language='javascript'>alert('邮箱格式不正确！');history.go(-1);</script>");
	}
	if(empty($code) || $code!=$_code){
		exit("<script language='javascript'>alert('验证码不正确！');history.go(-1);</script>");
	}
	$row=$db->get_row("select * from ".C('DB_PREFIX')."users where user='$name' and mail='$email'");
	if($row['user']==''){
		exit("<script language='javascript'>alert('此邮箱与用户名不匹配！');history.go(-1);</script>");
	}
	$m_codes = base64_encode(authcode($row['user'].'||||'.time(),'ENCODE',$syskey));
	$date = date("Y年m月d日 H:i:s");
	$sub='密码找回邮件';//邮件标题
	$user=$row['user'];
	$msg="$user,您好。帮助你找回在&nbsp;".C('webname')."&nbsp;的密码!<br>请点击下面的连接完成设置新密码！<br><a href='http://".$p_url."/setp.php?type=setp&code=$m_codes'>http://".$p_url."/setp.php?type=setp&code=$m_codes</a><br>(如果链接不能点击，请复制并粘贴到浏览器的地址栏，然后按回车键，此链接在48小时内有效。)<br/>----------<br/>".C('webname')."<br/>".$date;
	if(send_mail($m_user,$m_host,$m_port,$m_pwd,C('webname'),$row['mail'],$sub,$msg)){
		exit("<script language='javascript'>alert('重置密码链接已经发送至{$email}！请到邮箱查看连接，重设密码！');history.go(-1);</script>");
	}else{
		exit("<script language='javascript'>alert('邮件发送失败，请联系站长！');history.go(-1);</script>");
		}
	
	
}

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link href="/indexs/css/pace-theme-flash.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="/indexs/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/font-awesome.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/animate.min.css" rel="stylesheet" type="text/css"/>
<!-- END CORE CSS FRAMEWORK -->
<!-- BEGIN CSS TEMPLATE -->
<link href="/indexs/css/style.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/responsive.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/magic_space.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/custom-icon-set.css" rel="stylesheet" type="text/css"/>
<body class="error-body no-top lazy" style="background: url(/index/img/hero-bg.jpg);background-size: cover;"> 
<title>密码找回 - <?=C('webname')?></title>
<div class="container">
  <div class="row login-container animated fadeInUp">  
        <div class="col-md-8 col-md-offset-2 tiles white no-padding">
		 <div class="p-t-30 p-l-40 p-b-20 xs-p-t-10 xs-p-l-10 xs-p-b-10"> 
         <h2 class="normal"><?php if($msg){?><?=$msg?><?php }else{echo '<h2 class="normal">找回丢失的密码';}?></h2>
		  <p>目前,支持发送短信找回和电子邮箱找回..</p>
					<div class="checkbox checkbox check-success"> <a href="/login.php">已经找回成功?点击登录</a>&nbsp;&nbsp;
					</div>

		  </div>
		<div class="tiles grey p-t-20 p-b-20 text-black">
		<form id="frm_register" class="animated fadeIn" action="?type=findpwd" method="post">
                    <div class="row form-row m-l-20 m-r-20 xs-m-l-10 xs-m-r-10">
                      <div class="col-md-12">
                        <input name="name" tabindex="1" type="text" class="form-control" placeholder="用户名Username">
                      </div>
                    </div>
                    <div class="row form-row m-l-20 m-r-20 xs-m-l-10 xs-m-r-10">
                      <div class="col-md-12">
                        <input name="email" type="email" class="form-control" placeholder="邮箱Email">
                      </div>
                    </div>
                    <div class="row form-row m-l-20 m-r-20 xs-m-l-10 xs-m-r-10">
                      <div class="col-md-6 col-sm-6">
                        <input name="code" type="text" class="form-control" placeholder="验证码Reg code">
                      </div>
                      <div class="col-md-6 col-sm-6">
                        <img src="/code.php" onclick="javascript:this.src='/code.php?'+Math.random();" style="height:33px" />
                      </div>
					  <div class="col-md-10">
					    <button class="btn btn-primary btn-cons pull-right" type="submit">找回密码</button>
					  </div>
                    </div>
			</form>

		</div> 
		