<%@ page import="com.gx.soft.common.util.EncryptUtil" %>
<%@page contentType="text/html;charset=UTF-8" %>
<%@include file="/taglibs.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</title>
    <script
            src="<%=request.getContextPath()%>/gx/BJUI/js/jquery-1.7.2.min.js"></script>
    <script src="<%=request.getContextPath()%>/gx/BJUI/js/jquery.cookie.js"></script>
    <script src="<%=request.getContextPath()%>/gx/js/sha256.js"></script>
    <script src="<%=request.getContextPath()%>/gx/js/jsencrypt.min.js"></script>
    <script src="http://cdn.bootcss.com/jquery/1.12.3/jquery.min.js"></script>
    <script src="<%=request.getContextPath()%>/widgets/layer/layer.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/widgets/test/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/widgets/test/jquery.qrcode.min.js"></script>
    <link
            href="<%=request.getContextPath()%>/gx/BJUI/themes/css/bootstrap.min.css"
            rel="stylesheet">
    <style type="text/css">
        * {
            font-family: "Verdana", "Tahoma", "Lucida Grande", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
        }

        body {
            background: url(../gx/images/loginbg_02.jpg) no-repeat center center fixed;
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
        }

        .ewm {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 176px;
            height: 224px;
            margin-left: -490px;
            margin-top: -180px;
        }

        a:link {
            color: #285e8e;
        }

        .main_box {
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -180px;
            margin-left: -280px;
            padding: 30px;
            width: 560px;
            height: 400px;
            background: #FAFAFA;
            background: rgba(255, 255, 255, 0.5);
            border: 1px #DDD solid;
            border-radius: 5px;
            -webkit-box-shadow: 1px 5px 8px #888888;
            -moz-box-shadow: 1px 5px 8px #888888;
            box-shadow: 1px 5px 8px #888888;
        }

        .main_box .setting {
            position: absolute;
            top: 5px;
            right: 10px;
            width: 10px;
            height: 10px;
        }

        .main_box .setting a {
            color: #FF6600;
        }

        .main_box .setting a:hover {
            color: #555;
        }

        .login_logo {
            margin-bottom: 20px;
            height: 45px;
            text-align: center;
        }

        .login_logo img {
            height: 100px;
        }

        .login_msg {
            text-align: center;
            font-size: 16px;
        }

        .login_form {
            padding-top: 40px;
            font-size: 16px;
        }

        .login_box .form-control {
            display: inline-block;
            *display: inline;
            zoom: 1;
            width: auto;
            font-size: 18px;
        }

        .login_box .form-control.x319 {
            width: 280px;
        }

        .login_box .form-control.x120 {
            width: 120px;
        }

        .login_box .form-control.x164 {
            width: 179px;
        }

        .login_box .form-group {
            margin-bottom: 20px;
            margin-left: 70px
        }

        .login_box .form-group label.t {
            width: 70px;
            text-align: right;
            cursor: pointer;
        }

        .login_box .form-group img {
            margin-top: 1px;
            height: 32px;
            vertical-align: top;
        }

        .login_box .m {
            cursor: pointer;
        }

        .bottom {
            text-align: center;
            font-size: 12px;
        }
        .form-input{width:180px;height:34px;padding:6px 12px;font-size:14px;line-height:1.42857143;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075);-webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}
       /* .layui-layer-btn .layui-layer-btn0 {
            border-color: #0F192A;
            background-color: #428bca;
            color: #fff;
            width:180px;
            text-align: center;
            border-radius:5px;
            border: none;
            padding:10px;
            height:28px;
        }*/

    </style>
    <script type="text/javascript">
        var myVar,number=300;
        function changeQrcode(){
            $('#qrcode').html("");
            clearInterval(myVar);
            login_form=document.getElementById('login_form');
            login_form.style.display='none';
            mobile_login_form=document.getElementById('mobile_login_form');
            mobile_login_form.style.display='none';
            login_qrcode=document.getElementById('login_qrcode');
            login_qrcode.style.display='block';
            qrcode_login_logo=document.getElementById('qrcode_login_logo');
            qrcode_login_logo.style.display='none';
            normal_login_logo=document.getElementById('normal_login_logo');
            normal_login_logo.style.display='block';
            qrcodeFlush=document.getElementById('qrcodeFlush');
            qrcodeFlush.style.display='none';
            qrcode=document.getElementById('qrcode');
            qrcode.style.display='block';
            qrcode.style.opacity='1';
            scanSuccess=document.getElementById('scanSuccess');
            scanSuccess.style.display='none';
            scanTest=document.getElementById('scanTest');
            scanTest.style.display='block';
            //二维码生成
            var guuid = genuuid();
            $("#qrcode").qrcode({
                render: "canvas", // 渲染方式有table方式和canvas方式
                width: 120,   //默认宽度
                height: 120, //默认高度
                text:'http://10.0.0.138:8080/oa_ts/login/scan-check.do?uuid='+guuid, //二维码内容,此处直接使用生成的uuid,客户端自行拼接回调地址,调用登陆接口
                typeNumber: -1,   //计算模式一般默认为-1
                correctLevel: 2, //二维码纠错级别
                background: "#ffffff",  //背景颜色
                foreground: "#000000"  //二维码颜色

            });
            var margin = ($("#qrcode").height() - $("#qrCodeIco").height()) / 2; //控制Logo图标的位置
            $("#qrCodeIco").css("margin", margin);
            //长连接
            myVar = setInterval(function(){qrcodeValidity(guuid);}, 1000);

        }
        function changeNormal(){
            login_form=document.getElementById('login_form');
            login_form.style.display='block';
            mobile_login_form=document.getElementById('mobile_login_form');
            mobile_login_form.style.display='none';
            login_qrcode=document.getElementById('login_qrcode');
            login_qrcode.style.display='none';
            login_qrcode=document.getElementById('qrcode_login_logo');
            login_qrcode.style.display='block';
            login_qrcode=document.getElementById('normal_login_logo');
            login_qrcode.style.display='none';
            $('#qrcode').html("");
            clearInterval(myVar)
        }

        function qrcodeValidity(uuid) {
            console.info(uuid);
            $.ajax({
                url: '<%=basePath%>login/qr-long-connect-check.do',
                data: {
                    uuid:uuid
                },
                type: 'get',
                cache: false,
                dataType: 'json',
                success: function (json) {
                    if(json.statusCode==203){
                        qrcode=document.getElementById('qrcode');
                        qrcode.style.display='none';
                        scanTest=document.getElementById('scanTest');
                        scanTest.style.display='none';
                        scanSuccess=document.getElementById('scanSuccess');
                        scanSuccess.style.display='block';
                    }
                    if(json.statusCode==200){
                        clearInterval(myVar);
                        window.location.href=json.path;
                    }
                }
            });
            if (number-- == 0) {//时间到了 没有值,清空session中保存的验证码
                clearInterval(myVar);
                qrcodeFlush=document.getElementById('qrcodeFlush');
                qrcodeFlush.style.display='block';
                qrcode=document.getElementById('qrcode');
                qrcode.style.opacity='0.4';

                number = 300;
            }

        }

        //随机字符串的生成
        function genuuid() {
            var s = [];
            var hexDigits = "0123456789abcdef";
            for (var i = 0; i < 36; i++) {
                s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
            }
            s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
            s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
            s[8] = s[13] = s[18] = s[23] = "";
            var uuid = s.join("");
            return uuid;
        }
        //-----------------------------------------------
        //发送验证码
        function getVlidCode(){
            var mobile = $("#mobile").val();//将用户名作为session存储的key
            var mobile_login_info=$("#mobile-login-info");
            if(mobile==null){
                mobile="";
            }
            var mobile=$('#mobile').val();
            checkMobile(mobile);
            if (flog){
                $.ajax({
                    url: '<%=basePath%>login/getVerifYCode.do',
                    data: {
                        mobile: mobile,
                        requestName:'login'
                    },
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    success: function (json) {
                        if(json.statusCode==200){
                            mobile_login_info.text('');
                            totalNum=60;
                            chengeviyfValue('get-verify-code');
                        }else if(json.statusCode==300){
                            layer.msg("未绑定手机号,请用账号登录并绑定手机号",{time:1000});
                        }else if(json.statusCode==301){
                            mobile_login_info.text('您已在60秒内发过短信');
                        }
                    }
                });
            }
        }
        //校验手机号
        var flog=false;
        var flagT=true;
        function checkMobile(mobile) {
            if(mobile==null){
                mobile="";
            }
            var pre=/^[1][358][0-9]{9}$/;
            if(mobile==''){
                layer.msg("手机号不允许为空",{time:1000});
                return;
            }else{
                var pre=/^[1][358][0-9]{9}$/;
                if(!pre.test(mobile)){
                    layer.msg("手机号码格式有误",{time:1000});
                    return
                }else {
                    flog=true;
                }
            }
        }


        var COOKIE_NAME = 'sys__username';
        _BASE_PATH = '<%=basePath%>';
        $(function () {
            //获取cookie信息
            function getRememberInfo() {
                // alert("---获取cookie信息---");
                try {
                    var userName = "";
                    var userPassword = "";
                    userName = getCookieValue("oa_user_name");
                    userPassword = getCookieValue("oa_user_password");
                    $("#oa_user_name").val(userName);
                    $("#oa_user_password").val(userPassword);
                    if (userName.length > 0 && userPassword.length > 0) {
                        $("#rmbPassword").attr("checked", "checked");

                    }
                } catch (err) {
                    alert("NO RMB PASSWORD!");
                }
            }

            getRememberInfo();

            function loginfun() {
                var login_form = $("#login_form");
                var login_info = $("#login-info");
                login_info.text("");

                var jusername = $("#oa_user_name").val() || "";
                var jPwd = $("#oa_user_password").val() || "";
                if (jusername.length < 1 || jPwd.length < 1) {
                    login_info.text("请输入用户名或密码");
                } else {
                    var encrypt = new JSEncrypt();
                    encrypt.setPublicKey($("#publickey").val());
                    var encrypted = encrypt.encrypt(jPwd);
                    $.ajax({
                        url: '<%=basePath%>login/form-validate.do',
                        data: {
                            username: jusername,
                            pwd: encrypted

                        },
                        type: 'get',
                        cache: false,
                        dataType: 'json',
                        success: function (json) {
                            var _statusCode = json.statusCode;
                            if (_statusCode == "200") {
                                if (document.getElementById("rmbPassword").checked) {
                                    //alert("begin to rmb password!!!");
                                    setCookie("oa_user_name", jusername, 24, "/");
                                    setCookie("oa_user_password", jPwd, 24, "/");
                                    //alert("OK!COOKIE");
                                } else {
                                    deleteCookie("oa_user_name", "/");
                                    deleteCookie("oa_user_password", "/");
                                }
                                $("#login_ok").attr("disabled", true).val('登录中..');

                                login_form.submit();
                            } else if (_statusCode == "300") {
                                login_info.text("用户名或密码错误");
                            } else if (_statusCode == "301") {
                                login_info.text("当前用户已被锁定");
                            } else if (_statusCode == "302"){
                                //未绑定手机
                                layer.open({
                                    type:1,
                                    area:['400px', '240px'],
                                    btn:['确认','取消'],
                                    title:['绑定手机', 'font-size:15px;'],
                                    content:
                                            '<form action="<%=basePath%>login/mobile-bind-input.do" id="mobile-bind-input" method="post">' +
                                            '<div class="form-group" style="margin-left:25px;margin-top:30px;">' +
                                            '<label>手机号:</label> ' +
                                            '<input id="mobileNew" name="mobileNew" type="text" class="form-input"   autocomplete="off" placeholder="请输入手机号"/>' +
                                            '<button type="button" class="js-verify-code-send text-primary btn btn-default form-link" style="margin-left: 5px; margin-bottom: 5px;" id="getVerifyCode">获取验证码' +
                                            '</button>' +
                                            '</div>' +
                                            '<div class="form-group" style="margin-left:25px;margin-top:10px;">' +
                                            '<label for="verifyCode">验证码:</label> ' +
                                            '<input id="verifyCode" name="verifyCode" type="text" class="form-input"  autocomplete="off" placeholder="请输入验证码">' +
                                            '</div>' +
                                            '</from>',
                                    yes: function(index, layero){
                                        var mobile=document.getElementById("mobileNew").value;
                                        var verifyCode=document.getElementById("verifyCode").value;
                                        $.ajax({
                                            url: '<%=basePath%>login/mobile-bind-input.do',
                                            data: {
                                                userId: json.userId ,
                                                mobile: mobile,
                                                verifyCode:verifyCode,
                                                requestName:'bind'
                                            },
                                            type: 'post',
                                            cache: false,
                                            dataType: 'json',
                                            success: function (json) {
                                                if(json.status==200){
                                                    layer.close(index); //如果设定了yes回调,需进行手工关闭
                                                    $("#login_ok").attr("disabled", true).val('登录中..');
                                                    $("#login_form").submit();
                                                }else if(json.status==300){
                                                    layer.msg('手机号码格式有误');
                                                }else if(json.status==301){
                                                    layer.msg('验证码错误');
                                                }
                                            }
                                        });
                                    },
                                    btn2:function(){
                                        // layer.msg('取消');
                                    }
                                });
                                //给open的获取验证码绑定事件
                                $('#getVerifyCode').click(function (){
                                    var mobile = $("#mobileNew").val();//将用户名作为session存储的key
                                    checkMobile(mobile);
                                    if (flog){
                                            $.ajax({
                                            url: '<%=basePath%>login/getVerifYCode.do',
                                            data: {
                                                mobile: mobile,
                                                type: 'normal',
                                                requestName:'bind'
                                            },
                                            type: 'get',
                                            cache: false,
                                            dataType: 'json',
                                            success: function (json) {
                                                if(json.statusCode==200){
                                                    totalNum=60;
                                                    chengeviyfValue('getVerifyCode');
                                                }else if(json.statusCode==301){
                                                    layer.msg("您已在60秒内发过短信",{time:1000});
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    });
                }
            }

            //验证码登录验证 成功submit
            function mobileloginfun() {
                var mobile_login_form = $("#mobile_login_form");
                var mobile_login_info = $("#mobile-login-info");
                mobile_login_info.text("");

                var mobile = $("#mobile").val() || "";
                var verifyCode = $("#verify-code").val() || "";
                if (mobile.length != 11) {
                    mobile_login_info.text("手机号输入错误");
                } else {
                    var encrypt = new JSEncrypt();
                    encrypt.setPublicKey($("#publickey").val());
                    var encrypted = encrypt.encrypt(verifyCode);
                    $.ajax({
                        url: '<%=basePath%>login/mobile-form-validate.do',
                        data: {
                            mobile: mobile,
                            verifyCode: encrypted,
                            requestName:'login'
                        },
                        type: 'get',
                        cache: false,
                        dataType: 'json',
                        success: function (json) {
                            var _statusCode = json.statusCode;
                            if (_statusCode == "200") {
                                $("#mobile_login_ok").attr("disabled", true).val('登录中..');
                                mobile_login_form.submit();
                            } else if (_statusCode == "300") {
                                mobile_login_info.text("验证码错误");
                            } else if (_statusCode == "301") {
                                mobile_login_info.text("当前用户已被锁定");
                            }
                        }
                    });
                }
            }

            $("#login_ok").click(function () {
                loginfun();
            });

            $("#mobile_login_ok").click(function () {
                mobileloginfun();
            });

            $("input").on("keydown", function (e) {
                if (e.keyCode == 13) {
                    loginfun();
                }
            });
            /*$("#rmbPassword").bind("checked",function(){
                setCookie("oa_user_name",userName,24,"/");
                setCookie("oa_user_password",userPassword,24,"/");
            });
            GetLastUser();*/
        });

        function genTimestamp() {
            var time = new Date();
            return time.getTime();
        }



        //新建cookie。
        //hours为空字符串时,cookie的生存期至浏览器会话结束。hours为数字0时,建立的是一个失效的cookie,这个cookie会覆盖已经建立过的同名、同path的cookie(如果这个cookie存在)。
        function setCookie(name, value, hours, path) {
            var name = escape(name);
            var value = escape(value);
            var expires = new Date();
            expires.setTime(expires.getTime() + hours * 3600000);
            path = path == "" ? "" : ";path=" + path;
            _expires = (typeof hours) == "string" ? "" : ";expires=" + expires.toUTCString();
            document.cookie = name + "=" + value + _expires + path;
        }

        //获取cookie值
        function getCookieValue(name) {
            var name = escape(name);
            //读cookie属性,这将返回文档的所有cookie
            var allcookies = document.cookie;
            //查找名为name的cookie的开始位置
            name += "=";
            var pos = allcookies.indexOf(name);
            //如果找到了具有该名字的cookie,那么提取并使用它的值
            if (pos != -1) { //如果pos值为-1则说明搜索"version="失败
                var start = pos + name.length; //cookie值开始的位置
                var end = allcookies.indexOf(";", start); //从cookie值开始的位置起搜索第一个";"的位置,即cookie值结尾的位置
                if (end == -1) end = allcookies.length; //如果end值为-1说明cookie列表里只有一个cookie
                var value = allcookies.substring(start, end); //提取cookie的值
                return unescape(value); //对它解码
            } else return ""; //搜索失败,返回空字符串
        }

        //删除cookie
        function deleteCookie(name, path) {
            var name = escape(name);
            var expires = new Date(0);
            path = path == "" ? "" : ";path=" + path;
            document.cookie = name + "=" + ";expires=" + expires.toUTCString() + path;
        }

        function changeMobile(){
            login_form=document.getElementById('login_form');
            login_form.style.display='none';
            mobile_login_form=document.getElementById('mobile_login_form');
            mobile_login_form.style.display='block';
            login_qrcode=document.getElementById('login_qrcode');
            login_qrcode.style.display='none';
            login_qrcode=document.getElementById('qrcode_login_logo');
            login_qrcode.style.display='block';
            login_qrcode=document.getElementById('normal_login_logo');
            login_qrcode.style.display='none';
            clearInterval(myVar);
            $('#qrcode').html("");
        }

        function changeUser(){
            login_form=document.getElementById('login_form');
            login_form.style.display='block';
            mobile_login_form=document.getElementById('mobile_login_form');
            mobile_login_form.style.display='none';
            login_qrcode=document.getElementById('login_qrcode');
            login_qrcode.style.display='none';
            login_qrcode=document.getElementById('qrcode_login_logo');
            login_qrcode.style.display='block';
            login_qrcode=document.getElementById('normal_login_logo');
            login_qrcode.style.display='none';
            clearInterval(myVar);
            $('#qrcode').html("");
        }

        /**
         * 倒计时 t为倒计时标签id
         * @type {boolean}
         */

        var totalNum=60;
        function chengeviyfValue(t) {
            $("#"+t).text("剩余(" + totalNum + ")秒");
            $("#"+t).attr("disabled",true);
            if (totalNum == 0) {//时间到了 没有值,清空session中保存的验证码
                $("#"+t).attr("disabled",false);
                document.getElementById(t).innerHTML = "重新发送";
                totalNum = 60;
                flagT = true;
                return;
            } else {
                flagT = false;//当totalNum的值不等于0时,不让在点击发送按钮
            }
            totalNum--;
            setTimeout(function () {
                chengeviyfValue(t)
            }, 1000);

        }
        //忘记密码
        function forget(){
            layer.open({
                type:1,
                area:['410px', '345px'],
                btn:['确认','取消'],
                title:['忘记密码', 'font-size:15px;'],
                content:
                    '<form action="<%=basePath%>login/mobile-change-password.do" id="mobile-change-password" method="post">' +
                    '<div class="form-group" style="margin-left:25px;margin-top:30px;">' +
                    '<label>手机号:</label> ' +
                    '<input id="mobileNewForget" name="mobileNewForget" type="text" class="form-input"   autocomplete="off" placeholder="请输入手机号"/>' +
                    '<button type="button" class="js-verify-code-send text-primary btn btn-default form-link" style="margin-left: 5px; margin-bottom: 5px;" id="getVerifyCodeForget">获取验证码' +
                    '</button>' +
                    '</div>' +
                    '<div class="form-group" style="margin-left:25px;margin-top:10px;">' +
                    '<label for="verifyCodeForget">验证码:</label> ' +
                    '<input id="verifyCodeForget" name="verifyCodeForget" type="text" class="form-input"  autocomplete="off" placeholder="请输入验证码">' +
                    '</div>' +
                    '<div class="form-group" style="margin-left:25px;margin-top:-15px;">' +
                    '</br><label for="passwordForget">新密码:</label> ' +
                    '<input id="passwordForget" name="passwordForget" type="password" class="form-input" autocomplete="off" placeholder="请输入新密码">' +
                    '</div>' +
                    '<div class="form-group" style="margin-left:25px;margin-top:0px;">' +
                    '<label for="newPasswordForgetTwo" style="margin-left:-14px;">确认密码:</label> ' +
                    '<input id="newPasswordForgetTwo" name="newPasswordForgetTwo" type="password" class="form-input" autocomplete="off" placeholder="请再次输入新密码">' +
                    '</div>' +
                    '</from>',
                yes: function(index, layero){
                    var mobile=document.getElementById("mobileNewForget").value;
                    var verifyCode=document.getElementById("verifyCodeForget").value;
                    checkMobile(mobile);
                    if(!flog)return;
                    var encrypt = new JSEncrypt();
                    encrypt.setPublicKey($("#publickey").val());
                    var password = encrypt.encrypt($("#passwordForget").val());
                    var passwordTwo = encrypt.encrypt($("#newPasswordForgetTwo").val());
                    if(verifyCode==""){
                        layer.msg('验证码不允许为空',{time:1000});
                        return;
                    }
                    if($("#passwordForget").val()==""||$("#newPasswordForgetTwo").val()==""){
                        layer.msg('密码不允许为空',{time:1000});
                        return;
                    }
                    $.ajax({
                        url: '<%=basePath%>login/mobile-change-password.do',
                        data: {
                            mobile: mobile,
                            verifyCode:verifyCode,
                            password:password,
                            passwordTwo:passwordTwo,
                            requestName:'forget'
                        },
                        type: 'post',
                        cache: false,
                        dataType: 'json',
                        success: function (json) {
                            if (json.status == 200) {
                                layer.close(index); //如果设定了yes回调,需进行手工关闭
                                layer.msg('修改密码成功',{time:1000});
                            } else if (json.status == 300) {
                                layer.msg('未绑定账号',{time:1000});
                            } else if(json.status == 301){
                                layer.msg('验证码错误',{time:1000});
                            } else if(json.status == 302){
                                layer.msg('密码不一致,请重新输入',{time:1000});
                            } else if(json.status == 303){
                                layer.msg('密码不允许为空',{time:1000});
                            }
                        }
                    });
                }
            });
            //给open的获取验证码绑定事件
            $('#getVerifyCodeForget').click(function (){
                var mobile = $("#mobileNewForget").val();//将用户名作为session存储的key
                checkMobile(mobile);
                if (flog){
                    $.ajax({
                        url: '<%=basePath%>login/getVerifYCode.do',
                        data: {
                            mobile: mobile,
                            requestName:'forget'
                        },
                        type: 'get',
                        cache: false,
                        dataType: 'json',
                        success: function (json) {
                            if(json.statusCode==200){
                                totalNum=60;
                                chengeviyfValue('getVerifyCodeForget');
                            }else if(json.statusCode==300){
                                layer.msg("未绑定手机号,请用账号登录并绑定手机号",{time:1000});
                            }else if(json.statusCode==301){
                                layer.msg('您已在60秒内发过短信',{time:1000});
                            }
                        }
                    });
                }
            });
        }




    </script>
</head>
<body>
<div class="ewm"><img src="<%=basePath%>gx/images/ewm.png"></div>
<div class="main_box">
    <textarea id="publickey" style="display: none;">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgPjoInI06pM9xPeNOEj0imBUlpRZ1O5o4JzkHv108yspAe5sMtrOUGX2IzJ4dA3dxuMQnHoFyIw3KhmjgjB8RkwA9ctxNP5P83KbJUURFeK5MdBollgew5JSlUT+TCa2dsVjpbvtKIfjgunYMaF+c2j8nsmv9DC5WbPuwQM4PicEwi7Y9mqWD9c17ESzyIrtTb9WMtoo07edeKZvlc5eofSv8iAbdU5UPVY+24RqCbf02mgBp8S5PL6k3rXAiqWjKTwudlOLShjXkZBEpPaybJcO1hWjzBM4gU9FIokpV3MHj0qY4CsgY8Fh2w7H5a3pUuv0q9xKHg1ciCiPRKv6QQIDAQAB</textarea>
    <div id="normal_login_logo" style="display: none;position: absolute;margin-left: 469px;margin-top: -31px;">
        <img src="<%=basePath%>gx/images/conputer.png"  style="cursor:pointer;height: 60px;width: 60px;" onclick="changeNormal()">
    </div>
    <div id="qrcode_login_logo" style="float: right;margin-right: 29px;margin-top: -31px;">
        <img src="<%=basePath%>gx/images/qrcode.png" style="cursor:pointer;position: absolute;height: 60px;width: 60px;" onclick="changeQrcode()">
    </div>
    <div class="login_box">
        <div class="login_logo">
            <img src="<%=basePath%>gx/images/logo01.png">
        </div>
        <!--
      <c:if test="${!empty message}">
         <div class="login_msg">
             <font color="red">${message }</font>
          </div>
       </c:if>
        -->
        <div class="login_form">

            <input type="hidden" value="${randomKey }" id="j_randomKey"/>
            <form action="<%=basePath%>login/init-login.do" id="login_form"
                  method="post" name="login_form1">
                <input type="hidden" name="jfinal_token" value="${jfinal_token }"/>
                <div>
                    <label id="login-info"></label>
                </div>
                <div class="form-group">
                    <label for="oa_user_name" class="t">用户名:</label> <input
                        id="oa_user_name" name="userId" type="text"
                        class="form-control x319 in" autocomplete="off">
                </div>
                <div class="form-group">
                    <label for="oa_user_password" class="t">密   码:</label> <input
                        id="oa_user_password" name="password" type="password"
                        autocomplete="off" class="form-control x319 in">
                </div>
                <div class="form-group"
                     style="margin-left: 146px;height:25px; line-height:25px; margin-bottom: 5px;vertical-align:middle;">
                    <input type="checkbox" name="rmbPassword" id="rmbPassword"/>
                    <label for="rmbPassword" class="t">记住密码</label>     
                    <label text="forget" style="font-size: 16px;color:#333333;cursor: pointer;margin-left: 8px;" id="forget" onclick="forget();">忘记密码</label>
                </div>


                <div class="form-group space">

                    <input type="button" id="login_ok" value=" 登 录 "
                           class="btn btn-primary btn-lg" style="margin-left:75px"/>    
                    <input type="reset" class="btn btn-default btn-lg"
                           value=" 重 置 "/>
                    <label text="changeMobile" style="font-size: 16px;color:#4A8CDB;cursor: pointer;margin-left: 8px;" id="changeMobile" onclick="changeMobile();">验证码登录</label>
                </div>
            </form>

            <form action="<%=basePath%>login/mobile-login.do" id="mobile_login_form"
                  method="post" name="mobile_login_form1" style="display: none">
                <%--<input type="hidden" name="jfinal_token" value="${jfinal_token }"/>--%>
                    <div>
                        <label id="mobile-login-info"></label>
                    </div>
                    <div class="form-group">
                        <label for="mobile" class="t">手机号:</label> <input
                            id="mobile" name="mobile" type="text"
                            class="form-control x319 in" autocomplete="off" placeholder="请输入注册手机号码">
                    </div>
                    <div class="col-control">
                        <div class="form-group">
                            <label for="verify-code" class="t">验证码:</label> <input
                                id="verify-code" name="verifyCode" type="text"
                                class="form-control x164 in" autocomplete="off" placeholder="请输入验证码">
                            <button type="button" class="js-verify-code-send text-primary btn btn-default form-link"
                                    style="margin-bottom: 5px;"
                                    id="get-verify-code" onclick="getVlidCode()">获取验证码
                            </button>
                        </div>
                    </div>

                    <div class="form-group" style="margin-left: 268px;height:25px; line-height:25px; margin-bottom: 0px;vertical-align:middle;">

                    </div>


                    <div class="form-group space">
                        <input type="button" id="mobile_login_ok" value=" 登 录 "
                               class="btn btn-primary btn-lg" style="margin-left:75px"/>    
                        <input type="reset" class="btn btn-default btn-lg"
                               value=" 重 置 "/>
                        <label  text="changeUser" style="font-size: 16px;color:#4A8CDB;cursor: pointer;margin-left: 8px;" id="changeUser" onclick="changeUser();">账号登录</label>
                    </div>
            </form>

            <div class="qrcode" id="login_qrcode" style="display: none;width: 498px;height: 225px;">
<%--                二维码显示--%>
                <div id="qrcode" style="text-align:center;display: none;">
                </div>
<%--                二维码失效--%>
                <div id="qrcodeFlush" style="position:absolute;margin-left: 201px;margin-top: -96px;display: none;">
                    <span style="font-weight: bold">二维码已失效</span>
                    <input type="button" value="请点击刷新" onclick="changeQrcode()" style="display:block;width:80px;height:30px;background-color:#3b78dd;color:#fff;line-height:30px;border:0;border-radius:12px;font-size: 13px;margin-left: 8px;margin-top: 10px;" >
                </div>
<%--                二维码页面--%>
                <div id="scanTest" style="text-align: center;margin-top: 20px;display: none;">
                    <span>打开APP扫一扫登录</span>
                </div>
<%--             扫描二维码成功--%>
                <div id="scanSuccess" style="display: block;text-align:center;">
                    <img src='https://mimg.127.net/p/freemail/index/lib/img/applogin-scan-suc.png' style="width:90px;height:90px;">
                    <br/>
                    <span style="color: #33a853;line-height:22.4px;display: block;margin-top: 20px;">扫描成功,请在手机上确认登录</span>
                    <br/>
                    <label style="font-size: 14px;color:#5b8cca;cursor: pointer;display: block;margin-top: -10px;" onclick="changeQrcode();">返回二维码扫描</label>
                </div>

                <div id="qrcode_change" style="text-align: center;margin-top: 10px;">
                    <label  text="changeUser" style="font-size: 16px;color:#4A8CDB;cursor: pointer;margin-left: 8px;" id="changeUser_qrcode" onclick="changeUser();">账号登录</label>
                    <label text="changeMobile" style="font-size: 16px;color:#4A8CDB;cursor: pointer;margin-left: 8px;" id="changeMobile_qrcode" onclick="changeMobile();">验证码登录</label>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        Copyright © 2015 <a href="<%=basePath%>mobile-app/download.do" target="_blank">Android 客户端下载</a>  <a
            href="<%=basePath %>login/go-exam-login.do" target="_blank">在线考试登录</a>
    </div>
</div>
<script src="<%=basePath%>gx/js/browser.js"></script>
<script>
    if (browser.ie11below) {
        var _url = "<%=basePath%>login/go-browser-invalid.do";
        window.location.href = _url;
    }

</script>

</body>
</html>

 

后台

package com.gx.soft.sys.web;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Timestamp;

import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.gx.api.message.SendMessage;
import com.gx.soft.common.bean.ExpiryMap;
import com.gx.soft.common.util.EncryptUtil;
import com.gx.soft.common.util.HttpClient;
import com.gx.soft.common.util.Sha256;
import com.gx.soft.office.util.DateUtil;
import org.apache.ibatis.io.ResolverUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.gx.core.util.StringUtils;
import com.gx.soft.sys.persistence.domain.GxSysUser;
import com.gx.soft.sys.persistence.manager.SysUserManager;
import org.springframework.web.client.RestTemplate;

;

/**
 * 登录方法控制器
 *
 * @author optimus
 * @version 1.0
 */
@Controller
@RequestMapping("login")
@SessionAttributes("user_session")
// Session 注解
public class LoginController {
    // 日志
    private static Logger logger = LoggerFactory
            .getLogger(LoginController.class);
    @Resource(name = "sysUserManager")
    private SysUserManager sysUserManager;
    @Autowired
    private SendMessage sendMessage;

    /**
     * 前往登录页面跳转方法
     *
     * @param model
     * @return
     */
    @RequestMapping("go-login")
    public String goLogin(Model model) {

        return "redirect:/login/go-login-page.do";
    }

    @RequestMapping("go-exam-login")
    public String goExamLogin(Model model) {

        return "exam/login";
    }

    @RequestMapping("go-login-page")
    public String goLoginPage(Model model) {

        return "login/login-redirect";
    }

    @RequestMapping("go-browser-invalid")
    public String goBrowserInvalidPage(Model model) {

        return "login/browser-invalid";
    }

    @RequestMapping("go-login-index-page")
    public String goLoginIndexPage(Model model) {

        return "login/login";
    }

    /**
     * 登录验证
     *
     * @param model
     * @return
     */
    @RequestMapping("init-login")
    public String login(@RequestParam Map<String, Object> parameterMap, @RequestParam(required = false, defaultValue = "login") String opt,
                        Model model) {
        String url = "";
        List<GxSysUser> userList = sysUserManager.findBy("userId",
                parameterMap.get("userId"));
        if (userList.size() > 0) {
            url = "redirect:/home/go-home.do";
//       url = "redirect:/portal/template.do";
            GxSysUser user = userList.get(0);
            model.addAttribute("user_session", user);
        } else {
            url = "redirect:/login/go-login.do";
        }
        if (StringUtils.validateString(opt) && opt.equals("exam")) {
            url = "redirect:/exam/home/index.do";
        }

        return url;
    }

    /**
     * 登出
     *
     * @param model
     * @return
     */
    @RequestMapping("out-login")
    public String loginOut(@RequestParam Map<String, Object> parameterMap,
                           HttpServletRequest req, Model model) {
        HttpSession session = req.getSession(true);
        session.removeAttribute("user_session");
        String url = "redirect:/login/go-login-page.do";

        return url;
    }

    /**
     * 跳转修改密码页面
     *
     * @param parameterMap
     * @param req
     * @param model
     * @return
     */
    @RequestMapping("to-changepwd")
    public String toChangePwdPage(
            @RequestParam Map<String, Object> parameterMap,
            HttpServletRequest req, Model model) {

        return "sys/user/user-changepwd";
    }

    /**
     * 保存密码
     *
     * @param pass_sure
     * @param pass_new
     * @param pass_old
     * @param user
     * @param model
     * @return
     */
    @RequestMapping("changepwd-save")
    public @ResponseBody
    Map<String, Object> changePwd(String pass_sure, String pass_new,
                                  @RequestParam(defaultValue = "####") String pass_old, @ModelAttribute("user_session") GxSysUser user,
                                  Model model) {
        Map<String, Object> resMap = new HashMap<String, Object>();
        String statusCode = "200", message = "操作成功";
        try {
            if (pass_old.equals(user.getUserEnName())) {
                if (pass_new.equals(pass_sure)) {
                    user.setUserEnName(pass_new);
                    sysUserManager.save(user);
                } else {
                    message = "输入密码不一致";
                    statusCode = "300";
                }
            } else {
                message = "旧密码输入有误";
                statusCode = "300";
            }
        } catch (Exception e) {
            statusCode = "300";
            message = "操作失败";
            e.printStackTrace();
        }

        resMap.put("statusCode", statusCode);
        resMap.put("message", message);
        resMap.put("closeCurrent", true);

        return resMap;
    }

    /**
     * 原密码的校验
     *
     * @param pass_old
     * @param user
     * @param model
     * @return
     */
    @RequestMapping("validate-pwd")
    public @ResponseBody
    Map<String, Object> validatePwd(@RequestParam(defaultValue = "####")
                                            String pass_old, @ModelAttribute("user_session") GxSysUser user,
                                    Model model) {
        Map<String, Object> resMap = new HashMap<String, Object>();
        String statusCode = "ok", message = "输入正确";
        try {
            if (!pass_old.equals(user.getUserEnName())) {
                message = "旧密码输入有误";
                statusCode = "error";
            }
        } catch (Exception e) {
            statusCode = "error";
            message = "系统异常,请刷新系统后重试";
            e.printStackTrace();
        }

        resMap.put(statusCode, message);

        return resMap;
    }


    /**
     * 修改密码级别验证
     * @param pass_new
     * @param user
     * @param model
     * @return
     */
    @RequestMapping("passwordDifficulty")
    public @ResponseBody
    Map<String, Object> passwordDifficulty(@RequestParam(defaultValue = "####")
                                            String pass_new, @ModelAttribute("user_session") GxSysUser user,
                                    Model model) {
        Map<String, Object> resMap = new HashMap<String, Object>();
        String statusCode = "ok", message = "输入正确";
        String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$";
        try {
            if (!pass_new.matches(regex)) {
                message = "密码由字母数字组成8-16位";
                statusCode = "error";
            }
        } catch (Exception e) {
            statusCode = "error";
            message = "系统异常,请刷新系统后重试";
            e.printStackTrace();
        }

        resMap.put(statusCode, message);

        return resMap;
    }

    @RequestMapping(value = "form-validate", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody
    Map<String, Object> validateUserLogin(String username, String pwd) {
        String statusCode = "200";
        Map<String, Object> resMap = new HashMap<String, Object>();

        GxSysUser user = sysUserManager.findUniqueBy("userId", username);
        pwd = EncryptUtil.decryptByPrivateKey(pwd);
        if (user != null) {
            Integer errorCount = user.getErrorLoginCount();

            if (errorCount == null) {
                errorCount = 0;
            }
            //登录错误时间距今分钟数
            Long errorTimeBefore = DateUtil.getMinutesBefore(user.getErrorLoginTime());
            //登录次数大于等于3次,并且分钟数小于30分钟的,账户锁定
            long timeLock = 30L;
            if (errorCount >= 3 && errorTimeBefore < timeLock) {
                statusCode = "301";
            } else {
                if (pwd.equals(user.getUserEnName())) {
                    //登录成功后,重置错误时间和次数为0
                    user.setErrorLoginTime(null);
                    errorCount = 0;
                } else {
                    //如果错误时间大于30分钟,重新计数;否则累加
                    if (errorTimeBefore >= timeLock) {
                        errorCount = 0;
                    }
                    errorCount++;
                    user.setErrorLoginTime(new Timestamp(System.currentTimeMillis()));
                    statusCode = "300";
                }
                user.setErrorLoginCount(errorCount);
                sysUserManager.save(user);
            }
            //判断是否需要绑定手机
            if(statusCode.equals("200")){
                if(user.getUserMobileNum()==null||user.getUserMobileNum().equals("")){
                    statusCode="302";
                }
            }
        } else {
            statusCode = "300";
        }

        resMap.put("userId", username);
        resMap.put("statusCode", statusCode);
        return resMap;
    }

    /**
     * 前往用户的登录解锁
     *
     * @param rowId
     * @return
     */
    @RequestMapping(value = "user-unlock", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> devUnbind(String rowId) {
        Map<String, Object> resMap = new HashMap<String, Object>();
        String statusCode = "200", message = "操作成功";
        try {
            GxSysUser gxSysUser = sysUserManager.get(rowId);
            gxSysUser.setErrorLoginCount(0);
            gxSysUser.setErrorLoginTime(null);
            sysUserManager.save(gxSysUser);
        } catch (Exception e) {
            statusCode = "300";
            message = "操作失败";
            e.printStackTrace();
        }

        resMap.put("statusCode", statusCode);
        resMap.put("message", message);
        resMap.put("divid", "user-manager-user-list");
        return resMap;

    }

    /**
     * 发送验证码 SendMessage.send()发送短信
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "getVerifYCode", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody
    Map<String, Object> getVerifYCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String statusCode = "200";
        Map<String, Object> resMap = new HashMap<String, Object>();
        String mobile = request.getParameter("mobile");
        String type = request.getParameter("type");
        String requestName=request.getParameter("requestName");
        ExpiryMap<String, String> expiryMap = ExpiryMap.getInstance();
        boolean sendAgain = true;
        if (expiryMap.get(mobile + "webSendAgain"+requestName) != null) {
            sendAgain = false;
        }

        GxSysUser user = sysUserManager.findUniqueBy("userMobileNum", mobile);
        if (((type!=null&&type.equals("normal"))||user != null) && sendAgain) {
            String bit4Rand = randomCode();
            expiryMap.put("web"+mobile+requestName, bit4Rand, 300000);
            logger.error("[存入的验证码和key] key:" + mobile + " bit4Rand:" + bit4Rand);
            //发送短信
            String MessageResponse = sendMessage.send(mobile,bit4Rand);
        } else {
            //未绑定手机号
            statusCode = "300";
            //60s内禁止再次发生
            if (!sendAgain||(type!=null&&type.equals("normal"))) {
                statusCode = "301";
            }
        }
        if (sendAgain && statusCode.equals("200")) {
            expiryMap.put(mobile + "webSendAgain"+requestName, mobile, 60000);
        }

        resMap.put("statusCode", statusCode);
        return resMap;
    }

    /**
     * 手机登录验证
     *
     * @param request
     * @param mobile
     * @param verifyCode
     */
    @RequestMapping(value = "mobile-form-validate", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody
    Map<String, Object> validateMobileLogin(HttpServletRequest request, String mobile, String verifyCode,String requestName) {
        String statusCode = "200";
        Map<String, Object> resMap = new HashMap<String, Object>();
        GxSysUser user = sysUserManager.findUniqueBy("userMobileNum", mobile);
        verifyCode = EncryptUtil.decryptByPrivateKey(verifyCode);
        ExpiryMap<String, String> expiryMap = ExpiryMap.getInstance();
        if (user != null && expiryMap.get("web"+mobile+requestName) != null) {
            String vildCodeTwo = (String) expiryMap.get("web"+mobile+requestName);
            Integer errorCount = user.getErrorLoginCount();

            if (errorCount == null) {
                errorCount = 0;
            }
            //登录错误时间距今分钟数
            Long errorTimeBefore = DateUtil.getMinutesBefore(user.getErrorLoginTime());
            //登录次数大于等于3次,并且分钟数小于30分钟的,账户锁定
            long timeLock = 30L;
            if (errorCount >= 3 && errorTimeBefore < timeLock) {
                statusCode = "301";
            } else {
                if (verifyCode.equals(vildCodeTwo)) {
                    //登录成功后,重置错误时间和次数为0
                    user.setErrorLoginTime(null);
                    errorCount = 0;
                    //登录成功 清除
                    expiryMap.remove("web"+mobile+requestName);
                } else {
                    //如果错误时间大于30分钟,重新计数;否则累加
                    if (errorTimeBefore >= timeLock) {
                        errorCount = 0;
                    }
                    errorCount++;
                    user.setErrorLoginTime(new Timestamp(System.currentTimeMillis()));
                    statusCode = "300";
                }
                user.setErrorLoginCount(errorCount);
                sysUserManager.save(user);
            }

        } else {
            statusCode = "300";
        }

        resMap.put("statusCode", statusCode);
        return resMap;
    }



    /**
     * 手机登录跳转
     *
     * @param request
     * @param response
     * @param model
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "mobile-login", method = RequestMethod.POST)
    public String vlidCodeNum(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
        String vildCode = request.getParameter("verifyCode");
        String mobile = request.getParameter("mobile");
        logger.error("[校验验证码时出入的值]:vildCode:" + vildCode + " mobile:" + mobile);
        String url = "redirect:/home/go-home.do";
        GxSysUser user = sysUserManager.findUniqueBy("userMobileNum", mobile);
        model.addAttribute("user_session", user);
        return url;
    }

    /**
     * 登录页手机绑定
     *
     * @param userId
     * @param mobile
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "mobile-bind-input", method = RequestMethod.POST)
    public Map<String, Object> enterpriseSave(String userId, String mobile,String verifyCode,String requestName) {
        Map<String, Object> map = new HashMap<>();
        ExpiryMap<String, String> expiryMap = ExpiryMap.getInstance();
        String status = "200";
        String vildCodeTwo="";
        if (expiryMap.get("web"+mobile+requestName) != null) {
            vildCodeTwo = (String) expiryMap.get("web"+mobile+requestName);
        }
        GxSysUser gxSysUser = sysUserManager.findUniqueBy("userId", userId);
        String pre="^[1][358][0-9]{9}$";
        if (!mobile.matches(pre)){
            status="300";
        }else {
            if (vildCodeTwo.equals(verifyCode)&&gxSysUser != null) {
                gxSysUser.setUserMobileNum(mobile);
                sysUserManager.save(gxSysUser);
                expiryMap.remove("web"+mobile+requestName);
            }else {
                status="301";
            }
        }


        map.put("status", status);
        return map;
    }

    /**
     * 首页忘记密码
     * @param mobile
     * @param verifyCode
     * @param password
     * @param passwordTwo
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "mobile-change-password", method = RequestMethod.POST)
    public Map<String, Object> mobileChangePassword(String mobile,String verifyCode,String password,String passwordTwo,String requestName) {
        Map<String, Object> map = new HashMap<>();
        ExpiryMap<String, String> expiryMap = ExpiryMap.getInstance();
        String status = "200";
        String vildCodeTwo="";
        password=EncryptUtil.decryptByPrivateKey(password);
        passwordTwo=EncryptUtil.decryptByPrivateKey(passwordTwo);
        if (expiryMap.get("web"+mobile+requestName) != null) {
            vildCodeTwo = (String) expiryMap.get("web"+mobile+requestName);
        }
        GxSysUser gxSysUser = sysUserManager.findUniqueBy("userMobileNum", mobile);
        String pre="^[1][358][0-9]{9}$";
        if(gxSysUser!=null){
            if(verifyCode.equals(vildCodeTwo)){
                if(password.equals(passwordTwo)&&!(passwordTwo.equals("")||password.equals(""))){
                    gxSysUser.setUserEnName(password);
                    sysUserManager.save(gxSysUser);
                    expiryMap.remove("web"+mobile+requestName);
                }else {
                    status="302";
                    if(passwordTwo.equals("")||password.equals("")){
                        status="303";
                    }
                }
            }else {
                status="301";
            }
        }else {
            status="300";
        }
        map.put("status", status);
        return map;
    }

    /**
     * 扫码登录长连接,判断是否扫过码,手机端是否确认登录
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping(value = "qr-long-connect-check", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> QRLongConnectCheck(HttpServletRequest request, HttpServletResponse response,Model model) {
        String statusCode = "300";
        Map<String, Object> resMap = new HashMap<String, Object>();
        String uuid = request.getParameter("uuid");
        ExpiryMap<String, Object> expiryMap = ExpiryMap.getInstance();
        String status =(String)expiryMap.get("status"+uuid);
        GxSysUser gxSysUser =(GxSysUser)expiryMap.get(uuid);
        if(status!=null){
            statusCode="203";
            if(!StringUtils.isEmpty(gxSysUser)){
                model.addAttribute("user_session", gxSysUser);
                statusCode="200";
                resMap.put("path","http://localhost:8080/oa_ts/home/go-home.do");
            }
        }

        resMap.put("statusCode", statusCode);
        return resMap;
    }

    /**
     * 扫码登录,确定已经扫过码
     * @param uuid
     */
    @RequestMapping(value = "scan-check", method = RequestMethod.GET, produces = "application/json")
    public void scanCheck(String uuid){
        ExpiryMap<String, Object> expiryMap = ExpiryMap.getInstance();
        expiryMap.put("status"+uuid,"200",300000);
    }

    /**
     * 扫码登录,手机端确认,uuid绑定用户信息
     * @param uuid
     * @param userId
     * @param password
     */
    @RequestMapping(value = "bind-uuid-user", method = RequestMethod.GET, produces = "application/json")
    public void bindUuidUser(String uuid,String userId,String password){
        ExpiryMap<String, Object> expiryMap = ExpiryMap.getInstance();
        GxSysUser user = sysUserManager.findUniqueBy("userId", userId);
//        password = EncryptUtil.decryptByPrivateKey(password);
        if(user.getUserEnName().equals(password)){
            expiryMap.put(uuid,user,300000);
        }
    }


    /**
     * 6位随机验证码
     *
     * @return
     */
    public static String randomCode() {
        StringBuilder str = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            str.append(random.nextInt(10));
        }
        return str.toString();
    }

}