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 4a6630bacb
Refactored database, refactored config file, corrected login redirection
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.
2019-03-21 12:07:23 +01:00

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();
}
});
});