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/lib/js/login.js

38 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

function login ( ) {
var username = document.getElementById ( "form-username" ).value;
var password = document.getElementById ( "form-password" ).value;
hashedpassword = SHA512 ( password );
var xhr = new XMLHttpRequest ( );
xhr.open ( "POST", 'login', true );
xhr.onreadystatechange = function ( ) {
if ( xhr.status == 200 ) {
if ( xhr.readyState == XMLHttpRequest.DONE ) {
var response = xhr.responseText;
response = JSON.parse ( response );
if ( response [ 'status' ] == 200 ) {
window.location.href = script_name;
}
}
}
else {
document.getElementById ( 'login-response' ).innerHTML = JSON.parse ( xhr.responseText ) [ 'error_message' ];
setTimeout( function( ) {
document.getElementById ( 'login-response' ).innerHTML = ""
}, 1500 );
}
}
data = new FormData ( );
data.append('username', username);
data.append('password', password);
data.append('hashedpassword', hashedpassword);
xhr.send( data );
}
$(function ( ) {
$( '.form-group input' ).keyup( function ( e ) {
if ( e.keyCode == 13 ) {
login();
}
});
});