29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
|
function login() {
|
||
|
var username = document.getElementById ( "form-username" ).value;
|
||
|
var password = document.getElementById ( "form-password" ).value;
|
||
|
password = SHA512 ( password );
|
||
|
var xhr = new XMLHttpRequest ( );
|
||
|
xhr.open ( "POST", 'index.php', true );
|
||
|
xhr.onreadystatechange = function ( ) {
|
||
|
if ( xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200 ) {
|
||
|
if (xhr.status == 200) {
|
||
|
var response = xhr.responseText;
|
||
|
response = JSON.parse ( response );
|
||
|
if ( response [ 'status' ] == 200 ) {
|
||
|
window.location.href = "/";
|
||
|
}
|
||
|
else {
|
||
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'error_message' ];
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
console.log ( 'Server communication error: ' + xhr.statusText );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
data = new FormData ( );
|
||
|
data.append('username', username);
|
||
|
data.append('password', password);
|
||
|
xhr.send( data );
|
||
|
}
|