var auth;
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = Base64.encode(tok);
return "Basic " + hash;
}
function getAuthCookie() {
var cn = "Authorization=";
var idx = document.cookie.indexOf(cn)
var end;
if(idx != -1) {
var end = document.cookie.indexOf(";", idx + 1);
if(end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(idx + cn.length, end));
} else {
return "";
}
}
document.cookie = encodeURIComponent("Authorization") + "=deleted; expires=" + new Date(0).toUTCString();
auth = make_base_auth($.trim($('#email').val()), $.trim($('#password').val()));
document.cookie = "Authorization=" + auth;
$.ajax({
url : BASE_URI + "user",
method : "GET",
beforeSend : function(xhr) {
xhr.setRequestHeader('Authorization', getAuthCookie());
},
xhrFields : {
withCredentials : true
},
accept : "application/json",
contentType : "application/json",
cache : false,
cookie : false,
statusCode : {
404 : function() {
console.log("Page Not Found");
}
}
}).success(function(response) {
console.log("Login SUCCESS " + JSON.stringify(response));
}).fail(function(response) {
}).then(function() {
});