proxyauth: Use ajax instead of form submit
This commit is contained in:
+40
-16
@@ -59,23 +59,47 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="center">Cloudron Login</h1>
|
<h1 class="center">Cloudron Login</h1>
|
||||||
|
|
||||||
<form action="/login" method="post">
|
<table>
|
||||||
<table>
|
<tr>
|
||||||
<tr>
|
<td>Username:</td>
|
||||||
<td>Username:</td>
|
<td><input type="text" id="username" autofocus=""/></td>
|
||||||
<td><input type="text" name="username" autofocus=""/></td>
|
</tr>
|
||||||
</tr>
|
<tr>
|
||||||
<tr>
|
<td>Password:</td>
|
||||||
<td>Password:</td>
|
<td><input type="password" id="password"/></td>
|
||||||
<td><input type="password" name="password"/></td>
|
</tr>
|
||||||
</tr>
|
<tr>
|
||||||
<tr>
|
<td></td>
|
||||||
<td></td>
|
<td class="right"><input type="submit" value="Login" id="login" class="button"/></td>
|
||||||
<td class="right"><input type="submit" value="Login" class="button"/></td>
|
</tr>
|
||||||
</tr>
|
</table>
|
||||||
</table>
|
|
||||||
</form>
|
<p id="message"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function login() {
|
||||||
|
var username = document.getElementById('username').value;
|
||||||
|
var password = document.getElementById('password').value;
|
||||||
|
|
||||||
|
fetch('/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ username: username, password: password })
|
||||||
|
}).then(function (response) {
|
||||||
|
if (response.status === 401 || response.status === 403) {
|
||||||
|
document.getElementById('message').innerText = 'Invalid username or password';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.split('='); }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {});
|
||||||
|
window.location.href = search.redirect || '/';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
document.getElementById('username').addEventListener('keyup', function (e) { if (e.key === 'Enter') login(); });
|
||||||
|
document.getElementById('password').addEventListener('keyup', function (e) { if (e.key === 'Enter') login(); });
|
||||||
|
document.getElementById('login').addEventListener('click', function (e) { login(); });
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user