All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webapp.check-auth.js Maven / Gradle / Ivy

The newest version!
var rest_base='../..';
function updateAuthStatus(onSuccess){
		$.ajax({ 
			type: 'GET', 
			url: rest_base+'/auth/status',
			success: function(data) {
				// TODO remember token expiration date
				onSuccess();
			},
			error: function(xhr, s, e){
				console.log('Session abgelaufen: '+s);
				window.location.replace('login.html');
			},
			dataType: "xml"
		});
}
function getNodes(success, error){
	return $.ajax({ 
		type: 'GET', 
		url: rest_base+'/broker/node',
		success: function(data) {
			var a = [];
			var nodes = data.getElementsByTagNameNS('http://aktin.org/ns/exchange','node');
			for( var i=0; i',{href:'nodes.html#'+this.id, text:this.cn, title:this.dn});
					},
					seen: nodes[i].childNodes[2].innerHTML,
					websocket: nodes[i].childNodes[3].innerHTML
				});
			}
			success(a);
		},
		error: error,
		dataType: "xml"
	});	
}
$(document).ready(function(){
	// check if cookie is set
	var token = Cookies.get('token');
	if( token ){
		$.ajaxSetup({beforeSend: function (xhr){
			xhr.setRequestHeader("Authorization","Bearer "+token);        
		}});
		// cookie still valid?
		updateAuthStatus(init);
	}else{
		// no token cookie, redirect to login
		window.location.replace('login.html');
	}
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy