From 1f23ea546e9d0bceef1db4f3e42ec996e64f8e1a Mon Sep 17 00:00:00 2001
From: Wolfgang Knopki <wolfgang.knopki@hft-stuttgart.de>
Date: Tue, 10 Dec 2019 13:48:05 +0100
Subject: [PATCH] user profile fetch

---
 js/headfoot.js | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/js/headfoot.js b/js/headfoot.js
index d9755bd..97a05a4 100755
--- a/js/headfoot.js
+++ b/js/headfoot.js
@@ -23,6 +23,26 @@ function userAuthenticated(){
     }
 }
 
+var user = false;
+
+function profileExists(){
+    
+    $.get( "/api/v1/profile", function(data) {
+        let email = data.email
+        
+        if(email != ''){
+            user = true;
+        }
+    })
+    .done(function() {
+        console.log("done fetching profile info");
+    })
+    .fail(function() {
+        console.log( "error fetching profile info" );
+    })
+    return user;
+}
+
 
 function readCookie(cname) {
   var name = cname + "=";
@@ -129,12 +149,7 @@ function head(){
                 headlink.innerHTML="Account";
                 headlink.href="/account/";
             }
-            if(typeof user !== 'undefined' && user){
-                console.log(user)
-            }else{
-                console.log("user not defined")
-            }
-            if(typeof user !== 'undefined' && user){ //user has priority
+            if(profileExists()){ //user has priority
                 headlink.innerHTML="Logout";
                 headlink.href="/account/logout";
             }
-- 
GitLab