0
0
This repository has been archived on 2020-11-15. You can view files and clone it, but cannot push or open issues or pull requests.
OpenShorte.old/js/login.js
Bryan Pedini 7acb2ca533
Refactored the website
Renamed "includes" to "templates"
Added .htaccess to redirect requests to index.php
Added function to split request URL into array
Corrected locations in scripts and pages
2019-02-07 12:36:44 +01:00

29 lines
1.1 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", 'login', 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 = script_name;
}
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 );
}