JSFiddle - React, Tailwind, and code Playground
by kougiland
HTML
/**
* @class
*
* FmdClient is a JavaScript client library wrapping the access to the RESTful Web Services for Fake Media Detection created within the lab courses
* "Unternehmensgruendung und Neue Medien" in WS 2011/12 and WS 2012/13 at Chair for Computer Science 5 (Databases & Information Systems) at RWTH Aachen University, Germany.
*
*
* @returns {FmdClient}
*/
function FmdClient(endpointUrl){
// store a couple of central resource URIs for later usage
this._serviceEndpoint = endpointUrl;
this._usersResource = this._serviceEndpoint + "users";
this._mediaResource = this._serviceEndpoint + "media";
this._appendRateResource = "/ratings";
// since RESTful Web Services are stateless by design, credentials will have to be sent
// with every HTTP request requiring authentication. However, users should only provide
// credentials once and then play the game. For that purpose we use a simple mechanism
// that stores credentials in the browser's local storage using a new HTML5 feature.
// Works with latest versions of Chrome and Firefox. On initialization of an FmdClient
// instance, we check, if credentials are stored in local storage and - if so - set two
// client fields _uid, _mail and _cred, which can be used for authentication in subsequent requests.
if(localStorage.getItem("fmdsuid") !== null && localStorage.getItem("fmdsmail") !== null){
this._uid = localStorage.getItem("fmdsuid");
this._cred = localStorage.getItem("fmdscred");
this._mail = localStorage.getItem("fmdsmail");
this._name = localStorage.getItem("fmdsname");
}
};
/**
* Determines if a user is currently logged in and returns a boolean value of
* true if a user is logged in, false else.
*
* @returns (boolean)
*/
FmdClient.prototype.isLoggedIn = function(){
if(typeof this._uid !== 'undefined' && typeof this._cred !== 'undefined' && this._uid!=""){
return true;
}...