<%@ page language="java" pageEncoding="UTF-8"
         contentType="text/html; charset=UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
    String basePath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>兰亭集智知识管理系统-密码修改</title>
    <jsp:include page="../../common/head.jsp"></jsp:include>
    <style type="text/css">
        .textbox{
            border: 1px solid #cccccc;
            -webkit-border-radius: 0px 0px 0px 0px;
            border-radius: 0px 0px 0px 0px;
        }
    </style>
</head>
<body>
<div  class="easyui-layout"  title="Register" style="width:100%;max-width:400px;padding:30px 60px;">
    <form id="ff">
    <div style="margin-bottom:20px">
        <label for="username" class="label-top">帐号:</label>
        <input id="username" class="easyui-textbox easyui-validatebox tb" value="<shiro:principal/>"  style="width:280px;height:37px;border: 1px solid #ccc;box-sizing: border-box;" data-options="readonly:true,editable:false">
    </div>
    <div style="margin-bottom:20px">
        <label for="oldpwd" class="label-top">原始密码:</label>
        <input id="oldpwd" class="easyui-passwordbox easyui-validatebox tb" style="width:280px;height:37px;border: 1px solid #ccc;box-sizing: border-box;" data-options="required:true,validType:'length[3,10]'">
    </div>
    <div style="margin-bottom:20px">
        <label for="newpwd" class="label-top">新密码:</label>
        <input id="newpwd" class="easyui-passwordbox easyui-validatebox tb"  style="width:280px;height:37px;border: 1px solid #ccc;box-sizing: border-box;" data-options="required:true,validType:'length[3,10]'">
    </div>
    <div style="margin-bottom:20px">
        <label for="confirpwd" class="label-top">确认新密码:</label>
        <input id="confirpwd" class="easyui-passwordbox easyui-validatebox tb" style="width:280px;height:37px;border: 1px solid #ccc;box-sizing: border-box;" data-options="required:true,validType:'length[3,10]'">
    </div>
        <div style="margin-bottom:20px">
            <label for="captcha" class="label-top">验证码:</label>
            <div style="height: 37px;">
            <input id="captcha" class="tb"   style="-moz-border-radius: 5px 5px 5px 5px;-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;width:150px;height:37px;border: 1px solid #95B8E7;box-sizing: border-box;vertical-align: middle;">
            <img id="captchaImage" src="<%=basePath%>/captcha/image.action" style="vertical-align: middle;"></div>
            <div style="clear: both;"></div>
        </div>
    </form>
    <div style="text-align:center;padding:5px 0">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">提交</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">清除</a>
    </div>
</div>
<style scoped="scoped">
    .tb{
        width:100%;
        margin:0;
        padding:5px 4px;
        border:1px solid #95B8E7;
        box-sizing:border-box;
    }
</style>
<script>
    $(function(){
        $('input.easyui-validatebox').validatebox({
            validateOnCreate: false,
            err: function(target, message, action){
                var opts = $(target).validatebox('options');
                message = message || opts.prompt;
                $.fn.validatebox.defaults.err(target, message, action);
            }
        });
    });
    function submitForm(){
        var win = null;
        $.ajax({
            type:"post",//请求方式
            url:"<%=basePath %>/user/json/password/modify.action",//发送请求地址
            timeout:30000,//超时时间：30秒
            dataType:"json",//设置返回数据的格式
            data: {id:$("#username").textbox("getValue"),password:$("#oldpwd").passwordbox("getValue"),newpsw:$("#confirpwd").passwordbox("getValue"),captcha:$("#captcha").val()},
            //请求成功后的回调函数 data为json格式
            beforeSend:function(XMLHttpRequest){
                win=$.messager.progress({
                    title:'信息校验',
                    msg:'正在修改用户信息...',
                    interval:500
                });
            },
            success:function(data){
                if(data.status==1){
                    $.toast({text: data.message,position:'mid-center',allowToastClose: false,loader: false,afterHidden: function () {
                        window.location.href ="<%=basePath%>/";
                    }});
                }else{
                    $.messager.alert('温馨提示',data.message);
                }
            },
            complete:function(XMLHttpRequest, textStatus){
                $.messager.progress('close');
            },
            //请求出错的处理
            error:function(){
                alert("请求出错");
            }
        });
    }
    function clearForm(){
        $('#ff').form('clear');
    }
    $("#captchaImage").click(function(){
        $(this).attr("src","<%=basePath%>/captcha/image.action?r="+ (new Date()).valueOf());
    });
</script>
</body>
</html>