<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>修改密码</title>
	<meta name="decorator" content="default"/>
    <script src="${ctxStatic}/jquery/md5.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#oldPassword").focus();

            $.validator.addMethod("checkPassword",function(value,element,params){
                var regExp = /^[0-9A-Za-z]{6,12}$/;
                return this.optional(element)||(regExp.test(value));
            },"密码必须为6-12位数字或大小写字母!");
            $("#inputForm").validate({
                rules : {
                    newPassword: {
                        checkPassword: true,
                    },
                    confirmNewPassword:{
                        checkPassword:true
                    }
                }
            });
            $("#oldPassword").keydown(function(){
                $("#span").empty();
                return;
            });

            $("#oldPassword").blur(function(){
                var val = $("#oldPassword").val();
                if(val==null || val.trim()=='' || val.length <3){
                    $("#span").empty();
                    return;
                }
                var password = $.md5(($("#oldPassword").val()));
                $.ajax({
                    type: "post",
                    url: "${ctx}/sys/register/validatePassword",
                    data: {'loginName':'${user.loginName}','password':password},
                    dataType:"text",
                    success: function(data) {
                        if(data=="false"){
                            $("#span").empty();
                            $("#span").html("密码不正确");
                            $("#oldPassword").focus();
                        }else if(data=="true"){
                            $("#span").empty();
                            $("#span").html("已通过验证");
                        }
                    }
                })
            });
		});
	</script>
	<style>
		.form-top{
			padding-top: 40px;
			margin-left: 15px;
			margin-right: 15px;
		}
        .help-inline{
            color: red;
            font-size: 12px;
        }
	</style>
</head>
<body>
	<form:form id="inputForm" modelAttribute="user" action="${ctx}/sys/user/modifyPwd"  method="post" class="form-horizontal form-group">
		<form:hidden path="id"/>
		<form:hidden path="home"/>
		<sys:message hideType="1" content="${message}"/>
		<div class="container1">
			<div class="form-top">
                <div class="layui-item layui-col-sm12">
                    <label class="layui-form-label"><span class="require-item">*</span>旧密码：</label>
                    <div class="layui-input-block">
                        <input id="oldPassword" name="oldPassword" type="password" value="" maxlength="50" minlength="3"  class="form-control layui-input required"/>
                        <span id="span" class="help-inline"></span>
                    </div>
                </div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label"><span class="require-item">*</span>新密码：</label>
					<div class="layui-input-block">
						<input id="newPassword" name="newPassword" type="password" value="" maxlength="12" class="form-control layui-input required"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label"><span class="require-item">*</span>确认密码：</label>
					<div class="layui-input-block">
						<input id="confirmNewPassword" name="confirmNewPassword" type="password" value="" maxlength="12" class="form-control layui-input required" equalTo="#newPassword"/>
					</div>
				</div>

			</div>
		</div>
	</form:form>
</body>
</html>