64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
<!DOCTYPE html>
 | 
						|
<html>
 | 
						|
    <head>
 | 
						|
        <meta charset="UTF-8">
 | 
						|
        <title>{{.i18n.wide}} - {{.i18n.login}}</title>
 | 
						|
    </head>
 | 
						|
    <body>
 | 
						|
        <input id="username" placeholder="{{.i18n.username}}"/>
 | 
						|
        <input id="password" type="password" placeholder="{{.i18n.password}}..."/>
 | 
						|
        <button onclick="login()">{{.i18n.login}}</button>
 | 
						|
        <div id="msg"></div>
 | 
						|
        <script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/jquery-2.1.1.min.js"></script>
 | 
						|
        <script type="text/javascript">
 | 
						|
            (function () {
 | 
						|
                $("#username").keydown(function (event) {
 | 
						|
                    if (event.which === 13) {
 | 
						|
                        if ($.trim($(this).val()) === "") {
 | 
						|
                            $("#msg").text("{{.i18n.login_failed}}");
 | 
						|
                        } else {
 | 
						|
                            $("#password").focus();
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    $("#msg").text('');
 | 
						|
                });
 | 
						|
 | 
						|
 | 
						|
                $("#password").keydown(function (event) {
 | 
						|
                    if (event.which === 13) {
 | 
						|
                        if ($.trim($(this).val()) === "") {
 | 
						|
                            $("#msg").text("{{.i18n.login_failed}}");
 | 
						|
                        } else {
 | 
						|
                            login();
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    $("#msg").text('');
 | 
						|
                });
 | 
						|
            })();
 | 
						|
 | 
						|
            var login = function () {
 | 
						|
                var request = {
 | 
						|
                    username: $("#username").val(),
 | 
						|
                    password: $("#password").val()
 | 
						|
                };
 | 
						|
                $.ajax({
 | 
						|
                    type: 'POST',
 | 
						|
                    url: '/login',
 | 
						|
                    data: JSON.stringify(request),
 | 
						|
                    dataType: "json",
 | 
						|
                    success: function (data) {
 | 
						|
                        if (!data.succ) {
 | 
						|
                            $("#msg").text('{{.i18n.login_failed}}');
 | 
						|
                            return;
 | 
						|
                        }
 | 
						|
 | 
						|
                        window.location.href = "/";
 | 
						|
                    }
 | 
						|
                });
 | 
						|
            }
 | 
						|
        </script>        
 | 
						|
    </body>
 | 
						|
</html>
 |