4a6630bacb
Moved database function in class "Database"; Corrected database-using webpages accordingly; Moved config file from PHP to JSON with more config variables; Corrected login page redirection on wrong username or password.
37 lines
1.2 KiB
JavaScript
37 lines
1.2 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 {
|
|
console.log ( 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 );
|
|
}
|
|
|
|
$(function ( ) {
|
|
$( '.form-group input' ).keyup( function ( e ) {
|
|
if ( e.keyCode == 13 ) {
|
|
login();
|
|
}
|
|
});
|
|
});
|