18dc9b18d3
Moved PHP files to "lib" folder Moved Javascript files to "lib" folder Moved login page inline CSS to "login.css" Moved database functions to class "Database" Removed the html template, compensated with a direct HTML code inside PHP "else" statement
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();
|
|
}
|
|
});
|
|
});
|