This commit is contained in:
Van 2015-03-21 18:10:53 +08:00
parent fce39ce4e2
commit bd1a2778c3
3 changed files with 80 additions and 72 deletions

View File

@ -180,12 +180,8 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
Password string
}{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error("login error: ", err)
succ = false
return
}
args.Username = r.FormValue("username")
args.Password = r.FormValue("password")
succ = false
for _, user := range conf.Users {

File diff suppressed because one or more lines are too long

View File

@ -37,9 +37,11 @@
</div>
<div class="form fn-right">
<div id="msg" class="fn-none"></div>
<input id="username" placeholder="Username"/><br/>
<input id="password" type="password" placeholder="Password"/><br/>
<button id="loginBtn" class="btn-white btn">{{.i18n.login}}</button>
<form id="loginForm">
<input id="username" name="username" placeholder="Username"/><br/>
<input id="password" name="password" type="password" placeholder="Password"/><br/>
<button id="loginBtn" type="submit" class="btn-white btn">{{.i18n.login}}</button>
</form>
</div>
</div>
</div>
@ -50,13 +52,21 @@
</div>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/jquery.form.js"></script>
<script type="text/javascript">
(function () {
(function () {
var contentH = $(window).height() - $(".footer").height() - $(".header").height() - 18;
$(".content").height(contentH)
.css("padding-top", (contentH - $(".content .fn-left").height()) / 2 + "px");
var login = function () {
$('#loginForm').submit(function () {
console.log(1);
var options = {
url: '/login',
type: 'POST',
dataType: 'json',
beforeSubmit: function () {
var username = $.trim($("#username").val());
var password = $.trim($("#password").val());
@ -69,17 +79,7 @@
$("#password").focus();
return false;
}
var request = {
username: username,
password: password
};
$.ajax({
type: 'POST',
url: '/login',
data: JSON.stringify(request),
dataType: "json",
},
success: function (data) {
if (!data.succ) {
$("#msg").text('{{.i18n.login_error}}').show();
@ -88,38 +88,36 @@
window.location.href = "/";
}
});
};
$('#loginForm').ajaxSubmit(options);
return false;
});
$("#username").keydown(function (event) {
if (event.which === 13) {
if ($.trim($(this).val()) === "") {
$("#msg").text("{{.i18n.login_error}}").show();
} else {
$("#password").focus();
return false;
}
} else {
$("#msg").hide();
}
}).focus();
$("#password").keydown(function (event) {
if (event.which === 13) {
if ($.trim($(this).val()) === "") {
$("#msg").text("{{.i18n.login_error}}").show();
} else {
login();
}
} else {
$("#msg").hide();
}
});
$("#loginBtn").click(function () {
login();
});
})();
})();
</script>
</body>
</html>