<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<%
	String path = request.getContextPath();
%>
<link rel="stylesheet" type="text/css" href="static/css/font/font-awesome.min.css">
<style type="text/css">
	.span {
		position: absolute;
		left: 50%;
		top: 50%;
		margin-top: 5px;
	}
	.help-inline{
	  color: #FF5151;
			  border-color: #FF5151;
	}
	.success .help-inline.ok:before {
	  content: "\f00c";
	  font-size: 16px;
	  font-family: FontAwesome;
	  font-weight: normal;
	  font-style: normal;
	  display: inline-block;
	}
</style>
	
<!-- Reset Password -->
<!-- COMPOSE MESSAGE MODAL -->
<div class="modal-dialog" id="pwd-dialog" style="width: 500px;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title"><i class="fa fa-envelope-o"></i>重置密码</h4>
        </div>
        <input name="reset_userId" id="reset_userId" type="hidden" value="${userId}" class="form-control">
        <div class="modal-body">
        	<div class="row form-group">
            	<div class="col-sm-4">
            		<label class="span">旧密码</label>
            	</div>
                <div class="col-sm-7"> 
                    <input name="old_password" id="old_password" type="password" class="form-control" placeholder="请输入旧密码">
                </div>
            </div>
            <div class="row form-group">
            	<div class="col-sm-4">
            		<label class="span">新密码</label>
            	</div>
                <div class="col-sm-7"> 
                    <input name="reset_password_one" id="reset_password_one" type="password" class="form-control" placeholder="请输入密码">
                </div>
            </div>
            <div class="row form-group">
                <div class="col-sm-4">
            		<label class="span">确认新密码</label>
            	</div>
                <div class="col-sm-7"> 
                    <input name="reset_password_two" id="reset_password_two" type="password" class="form-control" placeholder="请输入确认密码">
                	<span class="help-inline" id="reset_error"></span>
                </div>
            </div>
        </div>
        <div class="modal-footer">
         <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times"></i>取消</button>
		 <button type="button" class="btn btn-primary pull-left" id="submitResetPassword"><i class="fa fa-envelope"></i>确定</button>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
<script type="text/javascript">
	var path = '<%= path%>';
    $(function() {
     	// 重置密码取消
     	$('#reset_cancel').click(function(){
     		$('#reset_userId').val("");
     		$('#old_password').val("");
     		$('#reset_password_one').val(""); 
     		$('#reset_password_two').val("");
     		$('#reset_error').text("");
     		$("#reset_compose-modal").modal("hide");
     	});
  	 
        $('#submitResetPassword').click(function(){
	     	var userId = $('#reset_userId').val();
	     	var oldPassword = $('#old_password').val(); 
    		var passwordOne = $('#reset_password_one').val(); 
    		var passwordTwo = $('#reset_password_two').val();
    		if(oldPassword==''){
    			$('#reset_error').text("");
    			$('#reset_error').text("请输入旧密码！")
    			return false;
    		}
    		if(passwordOne==''){
    			$('#reset_error').text("");
    			$('#reset_error').text("请输入新密码！");
    			return false;
    		}
    		if(passwordTwo==''){
    			$('#reset_error').text("");
    			$('#reset_error').text("请输入确认新密码！");
    			return false;
    		}
    		//新密码验证
    		if(passwordOne!=passwordTwo){
    			$('#reset_error').text("");
    			$('#reset_error').text("两次密码输入不一致,请重新输入！");
    			return false;
    		}
    		//新旧密码验证
    		if(oldPassword==passwordOne){
    			$('#reset_password_one').val(""); 
     			$('#reset_password_two').val("");
    			$('#reset_error').text("");
    			$('#reset_error').text("新旧密码不能相同,请重新输入！");
    			return false;
    		}
    		
    		//var aa=new RegExp("(?![a-z]+$|[0-9]+$)^[a-zA-Z0-9]{7,16}$");
    		if (passwordTwo.length < 6 || passwordTwo.length > 16){
    			$('#reset_error').text("");
    			$('#reset_error').text("密码长度为6-16个字符，且区分大小写");
    			return false;
    		}else{
    			$.ajax({
    				async: true,
    				url : 'system/user/resetUserPassword.do?userId='+userId+'&oldPassword='+oldPassword+'&passwordOne='+passwordOne+'&passwordTwo='+passwordTwo,
    				type : 'post',
    				contentType: 'application/json;utf-8',
    				dataType : 'json',
    				success : function(data) {
    					if(data!=''){
    						if(data!='1'){
    							if(data=='-1') {
    								$('#reset_error').text("非法修改密码，用户信息不一致！");
    							} else if(data=='-2') {
    								$('#reset_error').text("修改密码失败,新密码不一致！");
    							} else if(data=='-3') {
    								$('#reset_error').text("修改密码失败,旧密码不正确！");
    							} else if(data=='-4') {
    								$('#reset_error').text("修改密码失败,新旧密码不能相同！");
    							} else {
    								$('#reset_error').text("修改密码失败,请联系管理员！");
    							}
    						}else{
    							window.location.reload();
    							$('#reset_error').text("");
    							$("#pwd-dialog").hide();
    						}
    					}
    				}
    			});
    		}
        });
    });
</script>
