Fix #224
This commit is contained in:
parent
fce39ce4e2
commit
bd1a2778c3
|
@ -180,12 +180,8 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
Password string
|
Password string
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
args.Username = r.FormValue("username")
|
||||||
logger.Error("login error: ", err)
|
args.Password = r.FormValue("password")
|
||||||
succ = false
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
succ = false
|
succ = false
|
||||||
for _, user := range conf.Users {
|
for _, user := range conf.Users {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -37,9 +37,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="form fn-right">
|
<div class="form fn-right">
|
||||||
<div id="msg" class="fn-none"></div>
|
<div id="msg" class="fn-none"></div>
|
||||||
<input id="username" placeholder="Username"/><br/>
|
<form id="loginForm">
|
||||||
<input id="password" type="password" placeholder="Password"/><br/>
|
<input id="username" name="username" placeholder="Username"/><br/>
|
||||||
<button id="loginBtn" class="btn-white btn">{{.i18n.login}}</button>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,13 +52,21 @@
|
||||||
</div>
|
</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-2.1.1.min.js"></script>
|
||||||
|
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/jquery.form.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
(function () {
|
(function () {
|
||||||
var contentH = $(window).height() - $(".footer").height() - $(".header").height() - 18;
|
var contentH = $(window).height() - $(".footer").height() - $(".header").height() - 18;
|
||||||
$(".content").height(contentH)
|
$(".content").height(contentH)
|
||||||
.css("padding-top", (contentH - $(".content .fn-left").height()) / 2 + "px");
|
.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 username = $.trim($("#username").val());
|
||||||
var password = $.trim($("#password").val());
|
var password = $.trim($("#password").val());
|
||||||
|
|
||||||
|
@ -69,17 +79,7 @@
|
||||||
$("#password").focus();
|
$("#password").focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
var request = {
|
|
||||||
username: username,
|
|
||||||
password: password
|
|
||||||
};
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: '/login',
|
|
||||||
data: JSON.stringify(request),
|
|
||||||
dataType: "json",
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (!data.succ) {
|
if (!data.succ) {
|
||||||
$("#msg").text('{{.i18n.login_error}}').show();
|
$("#msg").text('{{.i18n.login_error}}').show();
|
||||||
|
@ -88,37 +88,35 @@
|
||||||
|
|
||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$('#loginForm').ajaxSubmit(options);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$("#username").keydown(function (event) {
|
$("#username").keydown(function (event) {
|
||||||
if (event.which === 13) {
|
if (event.which === 13) {
|
||||||
if ($.trim($(this).val()) === "") {
|
if ($.trim($(this).val()) === "") {
|
||||||
$("#msg").text("{{.i18n.login_error}}").show();
|
$("#msg").text("{{.i18n.login_error}}").show();
|
||||||
} else {
|
} else {
|
||||||
$("#password").focus();
|
$("#password").focus();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$("#msg").hide();
|
$("#msg").hide();
|
||||||
}
|
}
|
||||||
}).focus();
|
}).focus();
|
||||||
|
|
||||||
|
|
||||||
$("#password").keydown(function (event) {
|
$("#password").keydown(function (event) {
|
||||||
if (event.which === 13) {
|
if (event.which === 13) {
|
||||||
if ($.trim($(this).val()) === "") {
|
if ($.trim($(this).val()) === "") {
|
||||||
$("#msg").text("{{.i18n.login_error}}").show();
|
$("#msg").text("{{.i18n.login_error}}").show();
|
||||||
} else {
|
|
||||||
login();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$("#msg").hide();
|
$("#msg").hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#loginBtn").click(function () {
|
|
||||||
login();
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue