From 99db5699fb39d5b5a040d9325eb94fb1ec9d3278 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Mon, 2 Mar 2015 15:49:27 +0100 Subject: [PATCH] Handle anonymous users --- js/h5p-x-api-event.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/js/h5p-x-api-event.js b/js/h5p-x-api-event.js index 940a5cb..141e232 100644 --- a/js/h5p-x-api-event.js +++ b/js/h5p-x-api-event.js @@ -98,11 +98,33 @@ H5P.XAPIEvent.prototype.setObject = function(instance) { * Helper function to set the actor, email and name will be added automatically */ H5P.XAPIEvent.prototype.setActor = function() { - this.data.statement.actor = { - 'name': H5PIntegration.user.name, - 'mbox': 'mailto:' + H5PIntegration.user.mail, - 'objectType': 'Agent' - }; + if (H5PIntegration.user !== undefined) { + this.data.statement.actor = { + 'name': H5PIntegration.user.name, + 'mbox': 'mailto:' + H5PIntegration.user.mail, + 'objectType': 'Agent' + }; + } + else { + var uuid; + if (localStorage.H5PUserUUID) { + uuid = localStorage.H5PUserUUID; + } + else { + uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(char) { + var random = Math.random()*16|0, newChar = char === 'x' ? random : (random&0x3|0x8); + return newChar.toString(16); + }); + localStorage.H5PUserUUID = uuid; + } + this.data.statement.actor = { + 'account': { + 'name': uuid, + 'homePage': window.location.origin + H5PIntegration.basePath + }, + 'objectType': 'Agent' + }; + } }; /**