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
126
views/login.html
126
views/login.html
|
@ -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,76 +52,72 @@
|
||||||
</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 () {
|
||||||
var username = $.trim($("#username").val());
|
console.log(1);
|
||||||
var password = $.trim($("#password").val());
|
|
||||||
|
|
||||||
if (username === "") {
|
var options = {
|
||||||
$("#msg").text("{{.i18n.login_error}}").show();
|
url: '/login',
|
||||||
$("#username").focus();
|
type: 'POST',
|
||||||
return false;
|
dataType: 'json',
|
||||||
} else if (password === "") {
|
beforeSubmit: function () {
|
||||||
$("#msg").text("{{.i18n.login_error}}").show();
|
var username = $.trim($("#username").val());
|
||||||
$("#password").focus();
|
var password = $.trim($("#password").val());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = {
|
if (username === "") {
|
||||||
username: username,
|
$("#msg").text("{{.i18n.login_error}}").show();
|
||||||
password: password
|
$("#username").focus();
|
||||||
};
|
return false;
|
||||||
|
} else if (password === "") {
|
||||||
|
$("#msg").text("{{.i18n.login_error}}").show();
|
||||||
|
$("#password").focus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if (!data.succ) {
|
||||||
|
$("#msg").text('{{.i18n.login_error}}').show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
window.location.href = "/";
|
||||||
type: 'POST',
|
}
|
||||||
url: '/login',
|
};
|
||||||
data: JSON.stringify(request),
|
|
||||||
dataType: "json",
|
|
||||||
success: function (data) {
|
|
||||||
if (!data.succ) {
|
|
||||||
$("#msg").text('{{.i18n.login_error}}').show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$("#msg").hide();
|
|
||||||
}
|
|
||||||
}).focus();
|
|
||||||
|
|
||||||
|
|
||||||
$("#password").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 {
|
||||||
login();
|
$("#password").focus();
|
||||||
}
|
return false;
|
||||||
} else {
|
}
|
||||||
$("#msg").hide();
|
} else {
|
||||||
}
|
$("#msg").hide();
|
||||||
});
|
}
|
||||||
|
}).focus();
|
||||||
|
|
||||||
$("#loginBtn").click(function () {
|
$("#password").keydown(function (event) {
|
||||||
login();
|
if (event.which === 13) {
|
||||||
});
|
if ($.trim($(this).val()) === "") {
|
||||||
})();
|
$("#msg").text("{{.i18n.login_error}}").show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$("#msg").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue