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 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

View File

@ -3,11 +3,11 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{{.i18n.wide}} - {{.i18n.wide_title}}</title> <title>{{.i18n.wide}} - {{.i18n.wide_title}}</title>
<meta name="keywords" content="Wide, Golang, IDE, Team, Cloud, B3log, Login"/> <meta name="keywords" content="Wide, Golang, IDE, Team, Cloud, B3log, Login"/>
<meta name="description" content="A Web-based IDE for Teams using Golang, do your development anytime, anywhere."/> <meta name="description" content="A Web-based IDE for Teams using Golang, do your development anytime, anywhere."/>
<meta name="author" content="B3log"> <meta name="author" content="B3log">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/base.css?{{.conf.StaticResourceVersion}}"> <link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/base.css?{{.conf.StaticResourceVersion}}">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/sign.css?{{.conf.StaticResourceVersion}}"> <link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/sign.css?{{.conf.StaticResourceVersion}}">
<link rel="icon" type="image/x-icon" href="/favicon.ico" /> <link rel="icon" type="image/x-icon" href="/favicon.ico" />
@ -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 === "") {
$("#msg").text("{{.i18n.login_error}}").show();
$("#username").focus();
return false;
} else if (password === "") {
$("#msg").text("{{.i18n.login_error}}").show();
$("#password").focus();
return false;
}
var request = { var options = {
username: username, url: '/login',
password: password type: 'POST',
}; dataType: 'json',
beforeSubmit: function () {
var username = $.trim($("#username").val());
var password = $.trim($("#password").val());
$.ajax({ if (username === "") {
type: 'POST', $("#msg").text("{{.i18n.login_error}}").show();
url: '/login', $("#username").focus();
data: JSON.stringify(request), return false;
dataType: "json", } else if (password === "") {
success: function (data) { $("#msg").text("{{.i18n.login_error}}").show();
if (!data.succ) { $("#password").focus();
$("#msg").text('{{.i18n.login_error}}').show(); return false;
return; }
} },
success: function (data) {
if (!data.succ) {
$("#msg").text('{{.i18n.login_error}}').show();
return;
}
window.location.href = "/"; window.location.href = "/";
} }
}); };
};
$("#username").keydown(function (event) { $('#loginForm').ajaxSubmit(options);
if (event.which === 13) { return false;
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>