<link rel="stylesheet" type="text/css" href="static/nav-menu.css">
<script type="text/javascript">
$(document).ready(function () {
-
+ $("#login").submit(function () {
+ $("#login").login();
+ return false;
+ });
});
</script>
</head>
</div>
<!-- End header -->
- <div id="login">
+ <div id="login-container">
<div class="widget">
- <form id="login2" action="#">
+ <form id="login" action="#">
<p>
<label>
Username<br>
<p style="float:right; margin:0;">
<input type="submit" value="Log In">
</p>
+ <p id="result">
+
+ </p>
</form>
</div>
</div>
*/
mctx = {};
-mctx.api = location.protocol + "//" + location.host + "/api/";
+mctx.location = location.protocol + "//" + location.host;
+mctx.api = mctx.location + "/api/";
mctx.expected_api_version = 0;
-mctx.key = undefined;
mctx.has_control = false;
mctx.return_codes = {
$.fn.login = function () {
var username = this.find("input[name='username']").val();
var password = this.find("input[name='pass']").val();
- var force = this.find("input[name='force']").is(":checked");
- var url = mctx.api + "control";
-
- var authFunc = function(xhr) {
- xhr.setRequestHeader("Authorization",
- "Basic " + base64.encode(username + ":" + password));
+ var out = this.find("#result");
+ var redirect = function () {
+ window.location.href = mctx.location;
};
-
+
+ out.removeAttr("class");
+ out.text("Logging in...");
+
$.ajax({
- url : url,
- data : {action : "lock", force : (force ? true : undefined)},
- beforeSend : authFunc
+ url : mctx.api + "bind",
+ data : {user: username, pass : password}
}).done(function (data) {
- mctx.key = data.key;
- if (data.status < 0) {
- alert("no - " + data.description);
- } else {
- mctx.has_control = true;
- alert("yes - " + mctx.key);
- }
+ //todo: error check
+ mctx.has_control = true;
+ out.attr("class", "pass");
+ out.text("Login ok!");
+ setTimeout(redirect, 1000);
}).fail(function (jqXHR) {
- mctx.key = undefined;
mctx.has_control = false;
- alert("no");
+ out.attr("class", "fail");
+ out.text("Login request failed - connection issues.")
});
};
color: #0066BB;
}
+.pass {
+ color: #7AE309;
+ font-weight: bold;
+}
+
+.fail {
+ color: #E30909;
+ font-weight: bold
+}
+
div.centre {
text-align: center;
}
}
/** For login.html **/
-#login {
+#login-container {
margin: 0 auto;
width: 400px;
padding: 1.8em 0 0;
line-height: 1.8em;
}
-#login form {
+#login-container form {
padding: 1em 2em;
}
-#login input {
+#login-container input {
font-size: 24px;
}
-#login label {
+#login-container label {
font-size: 14px;
}
-#login input[type=submit], #login input[type=submit] {
+#login-container input[type=submit] {
font-size: inherit;
padding: 0.4em 0.8em;
+}
+
+#login-container #result {
+ clear: both;
}
\ No newline at end of file