<!DOCTYPE html>
<html lang="en">

<head>
	<!-- Required meta tags -->
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!--favicon-->
	<link rel="icon" href="static/image/favicon-32x32.png" type="image/png" />
	<!-- loader-->
	<link href="static/css/pace.min.css" rel="stylesheet" />
	<script src="static/js/pace.min.js"></script>
	<!-- Bootstrap CSS -->
	<link href="static/css/bootstrap.min.css" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
	<link href="static/css/app.css" rel="stylesheet">
	<link href="static/css/icons.css" rel="stylesheet">
	<link rel="stylesheet" href="static/css/toastr.min.css">
	<title>Login</title>
</head>

<body class="bg-lock-screen">
	<!-- wrapper -->
	<div class="wrapper">
		<div class="authentication-lock-screen d-flex align-items-center justify-content-center">
			<div class="card shadow-none bg-transparent">
				<div class="card-body p-md-5 text-center">
					<h1 class="text-white">FXMinerProxy</h1>
					<h2 class="text-white" id="H2Time">10:53 AM</h2>
					<h5 class="text-white" id="h5Date">Tuesday, January 14, 2021</h5>
					<div class="">
						<img src="static/image/user.png" class="mt-5" width="120" alt="" />
					</div>
					<p class="mt-2 text-white">{{.Administrator}}</p>
					<!-- <div class="mb-3 mt-3">
						<input type="text"     class="form-control" placeholder="用户名" />
					</div> -->
					<div class="mb-3 mt-3">
						<input type="password" id="password" class="form-control" placeholder="密码" />
					</div>
					<div class="d-grid">
						<button type="button" id="login_button" class="btn btn-white">登录</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- end wrapper -->
</body>
<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>
	var ServerTimeStamp = {{.TimeStamp}};
	function fn(v){
		var now = new Date(ServerTimeStamp*1000);
		var y = now.getFullYear();
		var m = now.getMonth();
		var d = now.getDate();
		var h = now.getHours();
		var mm = now.getMinutes();
		var s = now.getSeconds();
		var str;
		if(h>12) {
			h -= 12;
			str = " PM";
		}else{
			str = " AM";
		}
		h = h < 10 ? "0" + h : h;
		d = d < 10 ? "0" + d : d;
		m = m < 10 ? "0" + m : m;
		mm = mm < 10 ? "0" + mm : mm;
		s = s < 10 ? "0" + s : s;
		if (v ==1){
			var xy =  h + ":" + mm ;
			xy += str;
			return xy;
		}
		var xy =  m+"/"+d+","+y;
		return xy;
	}
	 document.getElementById("H2Time").innerText = fn(1);
	 document.getElementById("h5Date").innerText = fn(2);
	 $("#login_button").on("click", function () {
            var this_username = {{.Administrator}};
            var this_password = document.getElementById("password").value;
            if (this_username == "" || this_password == ""){
                toastrAll("请输入密码","错误","error");
                return;
            }
            var xhr = new XMLHttpRequest();
            var setCookie = new XMLHttpRequest();
            setCookie.onreadystatechange = function (){
                if (setCookie.readyState == 4 && setCookie.status == 200) {
                    window.location.href="/index";
                }
            }
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var data = xhr.responseText;
                    data = JSON.parse(data);
                    if (data.status == "ok"){
                        if (data.info == "login success"){
                            var new_data = 'username='+this_username+'&password='+this_password+'&token='+data.token;
                            setCookie.open('POST','api/setCookie',true);
                            setCookie.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                            setCookie.send(new_data);
                        }
                    }
                    else if (data.status == "err"){
                        toastrAll("密码错误","错误","error");
                    }
                }
            }
            var new_data = 'username='+this_username+'&password='+this_password;
            xhr.open('POST','api/login',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>

</html>