[add] Logout

Also made general fixes to the css
This commit is contained in:
2018-08-12 10:03:25 -06:00
parent de84da4482
commit d4fadf08bc
6 changed files with 48 additions and 33 deletions

View File

@@ -0,0 +1,18 @@
function logout() {
var baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/session/logout',
type: 'GET',
dataType: 'json',
success:function(data){
window.location.replace(baseUrl + '/html/login.php');
},
error:function(x) {
if (x.status==500){
$('#modalLoginError').modal('show');
document.getElementById('modalLoginErrorBody').innerHTML = "The user or password didnt match, please try again";
}
},
});
}

View File

@@ -1,26 +1,38 @@
/**
* Maps the enter key to the login action
*/
$(document).keypress(function(e) {
if(e.which == 13) {
processLogin();
}
});
/**
* Takes the input from the username and password fields and send theem to the backend
* to be validated
*
* The response from the api will contain a status that will determine if the login was
* successful or not and a message that will contain feedback which can be used to
* display errors to the user
*/
function processLogin() {
var baseUrl = getbaseUrl();
var parametros = {
var parameters = {
"userName":$('#userName').val(),
"password":$('#password').val()
};
$.ajax({
url: baseUrl + '/index.php/api/session/login',
url: baseUrl + '/api/session/login',
type: 'POST',
dataType: 'json',
data: parametros,
data: parameters,
success:function(data){
console.log(JSON.stringify(data));
if(data["status"] == "success"){
redirect(baseUrl + '/html/landing.php');
window.location.replace(baseUrl + '/html/landing.php');
}else if(data["status"] == "success" || (data["status"] === undefined)){
$('#modalLoginError').modal('show');
document.getElementById('modalLoginErrorBody').innerHTML = "The server didn't respond in time, please try again or refresh this page.";
@@ -33,8 +45,4 @@ function processLogin() {
}
},
});
}
function redirect(url){
window.location.replace(url);
}