<?php
include_once "./config.php";
if(@$_POST['userName']){
    $conn = new mysqli($db_ip, $db_name, $db_psd, "mysdk");
    $user = mysqli_query($conn,"SELECT * FROM t_account WHERE uname='" . $_POST['userName'] . "' and passwd='".$_POST['oldPwd']."' limit 1");
    if($user&&mysqli_num_rows($user)>0) {  
    mysqli_query($conn,"update t_account set passwd='".$_POST['newPwd']."' where uname='".$_POST['userName']."'");
    exit("修改成功！");
    }else{
        exit("修改失败，账号与原密码不匹配！");
    }
}

?>



<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>重置密码</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<link rel="stylesheet" href="style/weui.css">
<link rel="stylesheet" href="style/weuix.css">
<script src='./static/js/jquery-2.1.4.min.js' type='text/javascript'></script>
<style>
.page-bg {
	max-width: 750px;
	margin: 0 auto;
}
.weui-cells {
	margin-top:0;
	border: 1px solid #eee;
	border-radius: 1em;
}
.bgc-b{
	background-color:#fff;
}

</style>
</head>
<body  class="page-bg">
 
    <div class="weui-pay weui-cells_form">
        
         <div class="weui-cell none1 bgc-b">
            <p style="color:red"></p>
        </div>
		 <div class="weui-cell none1 bgc-b">
            <div class="weui-cell__hd"><label class="weui-label">&emsp;&emsp;&emsp;账号:</label></div>
            <div class="weui-cell__bd" >
                <input class="weui-input" style="height:80px"  name="user_name" id="user_name" type="text" placeholder="请确保输入正确">
            </div>
        </div>
        <div class="weui-cell none1 bgc-b">
            <div class="weui-cell__hd"><label class="weui-label">&emsp;&emsp;原密码:</label></div>
            <div class="weui-cell__bd" >
                <input class="weui-input" style="height:80px"  name="old_pwd" id="old_pwd" type="text" placeholder="请确保输入正确">
            </div>
        </div>
        <div class="weui-cell none1 bgc-b">
            <div class="weui-cell__hd"><label class="weui-label">&emsp;&emsp;新密码:</label></div>
            <div class="weui-cell__bd" >
                <input class="weui-input" style="height:80px"  name="new_pwd" id="new_pwd" type="text" placeholder="请输入">
            </div>
        </div>
        <div class="weui-cell none1 bgc-b">
            <div class="weui-cell__hd"><label class="weui-label">确认新密码:</label></div>
            <div class="weui-cell__bd" >
                <input class="weui-input" style="height:80px"  name="new_pwd1" id="new_pwd1" type="text" placeholder="请再次输入">
            </div>
        </div>
       
        <div class="weui-pay-btn">
            <button type="submit" class="weui-btn weui-btn_primary" style="background-color:#2196f3;" onclick="submit()">提交</button>
        </div>
    </div>
</div>
<div class="weui-footer weui-footer_fixed-bottom">
</div>
    <script type="text/javascript">
	

// 这个脚本是 ie6和ie7 通用的脚本
function custom_close() {
	if(confirm("您确定要关闭本页吗？")) {
		window.opener=null;
		window.open('','_self');
		window.close();
	} 
}

function submit() {
	var name=$("input[name=user_name]").val();
	var old=$("input[name=old_pwd]").val();
	var newPwd=$("input[name=new_pwd]").val();
	var newPwd1=$("input[name=new_pwd1]").val();

	if(!name) {
		alert("请输入账号！");
		return;
	}
	
	if(!old) {
		alert("请输入原密码！");
		return;
	}
	
	if(!newPwd) {
		alert("请输入新密码！");
		return;
	}
	
	if(!newPwd1) {
		alert("请再次输入新密码！");
		return;
	}
	if(newPwd1!=newPwd){
	    alert("新密码两次输入不一致，请重新输入！");
		return;
	}
	if(newPwd.length<6){
	    alert("新密码长度至少6位！");
		return;
	}
	$.ajax({
	    type:'post',
	    url:'./reset.php',
	    data:{
	        userName:name,oldPwd:old,newPwd:newPwd
	    },
	    success:function(res){
	        alert(res)
	    }
	})
	
    
}
</script>
</body>
</html>