<!DOCTYPE html>
<html lang="en" class="h-100">

<head>
    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="keywords" content="">
	<meta name="author" content="">
	<meta name="robots" content="">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="Fillow : Fillow Saas Admin  Bootstrap 5 Template">
	<meta property="og:title" content="Fillow : Fillow Saas Admin  Bootstrap 5 Template">
	<meta property="og:description" content="Fillow : Fillow Saas Admin  Bootstrap 5 Template">
	<meta name="format-detection" content="telephone=no">
	
	<!-- PAGE TITLE HERE -->
	<title>Fxpool Activation</title>
	
    <!-- FAVICONS ICON -->
    <link rel="stylesheet" href="static/css/toastr.min.css">
    <link href="static/css/style.css" rel="stylesheet">

</head>

<body class="vh-100" >
    <div class="authincation h-100">
        <div class="container h-100">
            <div class="row justify-content-center h-100 align-items-center">
                <div class="col-md-6">
                    <div class="authincation-content">
                        <div class="row no-gutters">
                            <div class="col-xl-12">
                                <div class="auth-form">
                                    <h4 class="text-center mb-4">试用结束,请激活你的账号</h4>
                                    <form action="index.html">
                                        <div class="mb-3">
                                            <label class="mb-1"><strong>UUID</strong></label>
                                            <input type="text" id="machine_code" value="{{.MachineCode}}" class="form-control">
                                        </div>
                                        <div class="mb-3">
                                            <label class="mb-1"><strong>激活码</strong></label>
                                            <input type="text" id="activation_code" class="form-control">
                                        </div>
                                        <div class="text-center">
                                            <button type="button" id="activation_button" class="btn btn-primary btn-block">激活</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!--**********************************
        Scripts
    ***********************************-->
    <!-- Required vendors -->
    <script src="static/js/global.min.js"></script>
    <script src="static/js/custom.min.js"></script>
    <script src="static/js/dlabnav-init.js"></script>
    <script src="static/js/toastr-init.js"></script>
    <script src="static/js/toastr.min.js"></script>
    <script>
         function reloadIndex(){
            window.location.href="/index";
        }
         $("#activation_button").on("click", function () {
            var this_activation_code = document.getElementById("activation_code").value;
            var this_machine_code = document.getElementById("machine_code").value;
            if (this_activation_code == "" ||this_machine_code== ""){
                toastrAll("不能为空","错误","error");
                return;
            }
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 400) {
                    window.location.href="/login";
                    return;
                }
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var data = xhr.responseText;
                    data = JSON.parse(data);
                    if (data.status == "ok"){
                        if (data.info == "Verify ok"){
                            toastrAll("激活成功正在重启等待3秒","成功","success");
                            var xh2 = new XMLHttpRequest()
                            xh2.open('GET','/api/reboot',true);
                            xh2.send();
                            setTimeout("reloadIndex()","3000");
                        }
                    }
                    else if (data.status == "err"){
                        if (data.info == "Verify error"){
                            toastrAll("激活失败,激活码不对","错误","error");
                        }
                        else if (data.info == "database error"){
                            toastrAll("激活失败,数据库连接出错","失败","error");
                        }
                        else if (data.info == "Has been activated"){
                            toastrAll("此UUID已经激活过了","失败","error");
                        }
                        else if (data.info == "no result"){
                            toastrAll("UUID不存在","失败","error");
                        }else{
                            toastrAll(data.info,"失败","error");
                        }
                    }
                }
            }
            var new_data = 'activation_code='+this_activation_code+'&machine_code='+this_machine_code;
            xhr.open('POST','/api/activation',true);
            xhr.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" );
            xhr.send(new_data);
         });
         function toastrAll(this_infostr,this_titlemsg,type){
            if (type == "info"){
                    toastr.info(this_infostr, this_titlemsg, {
                    positionClass: "toast-top-center",
                    timeOut: 5e3,
                    closeButton: !0,
                    debug: !1,
                    newestOnTop: !0,
                    progressBar: !0,
                    preventDuplicates: !0,
                    onclick: null,
                    showDuration: "300",
                    hideDuration: "1000",
                    extendedTimeOut: "1000",
                    showEasing: "swing",
                    hideEasing: "linear",
                    showMethod: "fadeIn",
                    hideMethod: "fadeOut",
                    tapToDismiss: !1
                });
            }else if(type == "success"){
                toastr.success(this_infostr, this_titlemsg, {
                        positionClass: "toast-top-center",
                        timeOut: 5e3,
                        closeButton: !0,
                        debug: !1,
                        newestOnTop: !0,
                        progressBar: !0,
                        preventDuplicates: !0,
                        onclick: null,
                        showDuration: "300",
                        hideDuration: "1000",
                        extendedTimeOut: "1000",
                        showEasing: "swing",
                        hideEasing: "linear",
                        showMethod: "fadeIn",
                        hideMethod: "fadeOut",
                        tapToDismiss: !1
                    });
            }else if(type == "error"){
                toastr.error(this_infostr, this_titlemsg, {
                        positionClass: "toast-top-center",
                        timeOut: 5e3,
                        closeButton: !0,
                        debug: !1,
                        newestOnTop: !0,
                        progressBar: !0,
                        preventDuplicates: !0,
                        onclick: null,
                        showDuration: "300",
                        hideDuration: "1000",
                        extendedTimeOut: "1000",
                        showEasing: "swing",
                        hideEasing: "linear",
                        showMethod: "fadeIn",
                        hideMethod: "fadeOut",
                        tapToDismiss: !1
                    });
            }
        }
        
    </script>
</body>
</html>