"name": "readifood/readifood",
"description": "Readifood",
"require": {
- "propel/propel1": "1.6.9"
+ "auth0/auth0-php": "~5.0",
+ "propel/propel1": "1.6.9",
+ "vlucas/phpdotenv": "2.4.0"
}
}
--- /dev/null
+<?php
+
+ use Auth0\SDK\Auth0;
+
+ $dotenv = new Dotenv\Dotenv($root);
+ $dotenv->load();
+
+ $AUTH0_AUDIENCE = getenv('AUTH0_AUDIENCE');
+ $AUTH0_CALLBACK_URL = getenv('AUTH0_CALLBACK_URL');
+ $AUTH0_CLIENT_ID = getenv('AUTH0_CLIENT_ID');
+ $AUTH0_CLIENT_SECRET = getenv('AUTH0_CLIENT_SECRET');
+ $AUTH0_DOMAIN = getenv('AUTH0_DOMAIN');
+ $AUTH0_LOGOUT_CALLBACK_URL = getenv('AUTH0_LOGOUT_CALLBACK_URL');
+
+ if (getenv("MEMCACHED")) {
+ ini_set("session.save_handler", "memcached");
+ ini_set("session.save_path", getenv("MEMCACHED"));
+ }
+
+ $auth0 = new Auth0([
+ 'domain' => $AUTH0_DOMAIN,
+ 'client_id' => $AUTH0_CLIENT_ID,
+ 'client_secret' => $AUTH0_CLIENT_SECRET,
+ 'redirect_uri' => $AUTH0_CALLBACK_URL,
+ 'audience' => $AUTH0_AUDIENCE,
+ 'scope' => 'openid profile',
+ 'persist_id_token' => true,
+ 'persist_access_token' => true,
+ 'persist_refresh_token' => true,
+ 'state_handler' => false
+ ]);
+
+?>
<div id="popup"></div>
</body>
</html>
-<?php session_write_close(); ?>
}
include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "admin.php")));
+ include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "auth0.php")));
include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "forms.php")));
?>
<a href="/report">Reports</a>
<strong class="small"><em><?php echo $username; ?></em>@<?php echo $charity; ?></strong>
-<a href="/logout" class="smaller">logout</a>
+<a href="/logout.php" class="smaller">logout</a>
<?php } else echo "<strong>$charity</strong>"; ?>
</p>
$_SESSION[$key] = $value;
}
- session_start();
-
?>
#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")));
?>
+++ /dev/null
-index.php
\ No newline at end of file
--- /dev/null
+<?php
+
+ $root = join(DIRECTORY_SEPARATOR, array($_SERVER['DOCUMENT_ROOT'], ".."));
+ $lib_root = join(DIRECTORY_SEPARATOR, array($root, "lib"));
+ require_once(join(DIRECTORY_SEPARATOR, array($root, "vendor", "autoload.php")));
+ include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "auth0.php")));
+
+ if (isset($_GET['code'])) {
+ try {
+ $auth0->getUser();
+ header("Location: https://" . $_SERVER['HTTP_HOST'] . "/");
+ exit;
+ }
+ catch (\Exception $e) {
+ }
+ }
+
+?>
--- /dev/null
+<?php
+
+ $root = join(DIRECTORY_SEPARATOR, array($_SERVER['DOCUMENT_ROOT'], ".."));
+ $lib_root = join(DIRECTORY_SEPARATOR, array($root, "lib"));
+ require_once(join(DIRECTORY_SEPARATOR, array($root, "vendor", "autoload.php")));
+ include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "auth0.php")));
+
+ $auth0->logout();
+ session_destroy();
+
+ $url = sprintf("https://%s/v2/logout?client_id=%s&returnTo=%s", $AUTH0_DOMAIN, $AUTH0_CLIENT_ID, $AUTH0_LOGOUT_CALLBACK_URL);
+ header('Location: ' . $url);
+
+?>