mirror of
https://github.com/YunoHost/SSOwat.git
synced 2024-09-03 20:06:27 +02:00
59 lines
1.9 KiB
HTML
59 lines
1.9 KiB
HTML
<html>
|
|
|
|
<center id="loginform" style="padding-top: 10em">
|
|
|
|
<p>
|
|
<label for="username"><b>Username</b></label>
|
|
<input id="username" type="text" placeholder="Enter Username" name="username" required>
|
|
</p>
|
|
|
|
<p>
|
|
<label for="password"><b>Password</b></label>
|
|
<input id="password" type="password" placeholder="Enter Password" name="password" required>
|
|
</p>
|
|
|
|
<button id="login">Login</button>
|
|
</center>
|
|
|
|
<center id="userdata" style="color:green;">
|
|
</center>
|
|
|
|
|
|
<script>
|
|
document.getElementById('login').onclick = function() {
|
|
var username = document.getElementById('username').value;
|
|
var password = document.getElementById('password').value;
|
|
|
|
let formData = new FormData();
|
|
formData.append("credentials", username + ":" + password);
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
xhr.open("POST", "/yunohost/portalapi/login")
|
|
xhr.setRequestHeader('X-Requested-With', ''); // CSRF protection
|
|
xhr.send(formData)
|
|
xhr.onload = function() {
|
|
if (xhr.status != 200) {
|
|
// handle error
|
|
alert( 'Error: ' + xhr.status);
|
|
return;
|
|
}
|
|
|
|
let xhr2 = new XMLHttpRequest();
|
|
xhr2.open("GET", "/yunohost/portalapi/me")
|
|
xhr2.setRequestHeader('X-Requested-With', ''); // CSRF protection
|
|
xhr2.send();
|
|
xhr2.onload = function() {
|
|
if (xhr2.status != 200) {
|
|
// handle error
|
|
alert( 'Error fetching /me: ' + xhr2.status);
|
|
return;
|
|
}
|
|
|
|
document.getElementById('userdata').innerHTML = xhr2.response;
|
|
};
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</html>
|
|
|