Support Auth0.
[readifood.git] / www / index.php
index f8434a9..d88b321 100644 (file)
   #echo "request: $request; module: $module; params: " . print_r($parameters, true);
 
   $http = (isset($_SERVER['HTTPS'])) ? "https" : "http";
-  $username = $_SERVER['REMOTE_USER'];
   include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "constants.php")));
   include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "functions.php")));
   include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "session.php")));
+
+  $auth0_user = $auth0->getUser();
+  if (isset($auth0_user)) $username = $auth0_user["sub"];
+  else $username = null;
+
   include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "header.php")));
-  $q = new UserQuery;
-  $user = $q->findOneByUsername($username);
-  if (! $q->count()) {
-    echo "<h1 class=\"printonly\">$charity</h1>\n";
-    echo "<h1>Not logged in!</h1>\n";
-    if ($_SERVER['REMOTE_USER']) echo "<p>User <em>" . $_SERVER['REMOTE_USER'] . "</em> needs an entry in the user table.</p>\n";
-  }
-  else {
-    $user_id = $user->getContactId();
-    $admin_level = $user->getAdmin();
-    if ($module) {
-      echo "<h3 class=\"printonly\">$charity $module</h3>\n";
-      include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "$module.php")));
+
+  if ($username) {
+    $q = new UserQuery;
+    $user = $q->findOneByUsername($username);
+    if (! $q->count()) {
+      echo "<h1 class=\"printonly\">$charity</h1>\n";
+      echo "<h1>Not logged in!</h1>\n";
+      echo "<p>User <em>$username</em> needs an entry in the user table.</p>\n";
     }
+    else {
+      $user_id = $user->getContactId();
+      $admin_level = $user->getAdmin();
+      if ($module) {
+        echo "<h3 class=\"printonly\">$charity $module</h3>\n";
+        include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "$module.php")));
+      }
 
-    #else include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "menu.php")));
-   }
+      #else include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "menu.php")));
+    }
+  }
+  else $auth0->login();
   include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "footer.php")));
 ?>