Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02c397bca2 | |||
| a4ae987f94 | |||
|
|
26c4f801d3 | ||
|
|
49581da52c | ||
| 57faf21a67 | |||
| 5ff90e0d78 |
@@ -13,3 +13,5 @@ OIDC_HOST = ""
|
||||
OIDC_CLIENT_ID = ""
|
||||
OIDC_CLIENT_SECRET = ""
|
||||
OIDC_DISABLE_SSL = ""
|
||||
|
||||
SENTRY_ENVIRONMENT = ""
|
||||
@@ -2,6 +2,7 @@
|
||||
"require": {
|
||||
"ramsey/uuid": "^4.0",
|
||||
"vlucas/phpdotenv": "^5.0",
|
||||
"jumbojett/openid-connect-php": "^0.9.0"
|
||||
"jumbojett/openid-connect-php": "^0.9.0",
|
||||
"sentry/sdk": "^2.1"
|
||||
}
|
||||
}
|
||||
|
||||
1785
app/composer.lock
generated
1785
app/composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,44 @@
|
||||
return $version;
|
||||
}
|
||||
|
||||
function oidc_set_vars($sub, $uid, $fname, $lname, $email)
|
||||
{
|
||||
$_SESSION['uuid'] = $sub;
|
||||
$_SESSION['username'] = $uid;
|
||||
$_SESSION['given_name'] = $fname;
|
||||
$_SESSION['family_name'] = $lname;
|
||||
$_SESSION['full_name'] = $fname . " " . $lname;
|
||||
$_SESSION['email'] = $email;
|
||||
}
|
||||
|
||||
function is_signed_in()
|
||||
{
|
||||
if (isset($_SESSION['is_signed_in'])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function user_exists($db, $uuid)
|
||||
{
|
||||
try {
|
||||
$sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid");
|
||||
$sql->bindParam(':uuid', $uuid);
|
||||
$sql->execute();
|
||||
$sql->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$result = $sql->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
throw new Exception("Error in user_exists(): " . $e->getMessage());
|
||||
die();
|
||||
}
|
||||
if (empty($result)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function get_all_users($db)
|
||||
{
|
||||
try {
|
||||
@@ -15,7 +53,8 @@
|
||||
$sql->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$result = $sql->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
echo("Error: " . $e->getMessage());
|
||||
throw new Exception("Error in get_all_users(): " . $e->getMessage());
|
||||
die();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -31,7 +70,8 @@
|
||||
$result = $sql->fetchAll();
|
||||
$usr = $result[0]['given_name'] . " " . $result[0]['family_name'];
|
||||
} catch (PDOException $e) {
|
||||
echo("Error: " . $e->getMessage());
|
||||
throw new Exception("Error in get_user_name(): " . $e->getMessage());
|
||||
die();
|
||||
}
|
||||
return $usr;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<?php
|
||||
echo($_ENV['APP_NAME'] . " " . get_version());
|
||||
if ($_ENV['APP_NAME'] != "FHeD") {
|
||||
echo(", powered by FHeD");
|
||||
echo("| Powered by FHeD");
|
||||
};
|
||||
?><br>
|
||||
<?php if (is_signed_in()) {
|
||||
|
||||
@@ -7,6 +7,15 @@ require_once __DIR__ . "/../vendor/autoload.php";
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . "/..");
|
||||
$dotenv->load();
|
||||
|
||||
// Custom functions
|
||||
require_once __DIR__ . "/app_functions.php";
|
||||
|
||||
// Sentry
|
||||
Sentry\init([
|
||||
'dsn' => 'https://8d8f4632fe3e4ec9b005a1b60b660ba5@o435706.ingest.sentry.io/5395475',
|
||||
'release' => get_version(),
|
||||
]);
|
||||
|
||||
// Database auto-generation
|
||||
if (file_exists("/../includes/install.php")) {
|
||||
return;
|
||||
@@ -34,25 +43,3 @@ if ($_ENV['OIDC_DISABLE_SSL'] == "true") {
|
||||
$oidc->setVerifyHost(false);
|
||||
$oidc->setVerifyPeer(false);
|
||||
}
|
||||
|
||||
|
||||
// Custom functions
|
||||
|
||||
require_once __DIR__ . "/app_functions.php";
|
||||
|
||||
function oidc_set_vars($sub, $uid, $fname, $lname, $email) {
|
||||
$_SESSION['uuid'] = $sub;
|
||||
$_SESSION['username'] = $uid;
|
||||
$_SESSION['given_name'] = $fname;
|
||||
$_SESSION['family_name'] = $lname;
|
||||
$_SESSION['full_name'] = $fname . " " . $lname;
|
||||
$_SESSION['email'] = $email;
|
||||
}
|
||||
|
||||
function is_signed_in() {
|
||||
if (isset($_SESSION['is_signed_in'])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
// Perform the OIDC authentication
|
||||
try {
|
||||
$oidc->authenticate();
|
||||
$_SESSION['access_token'] = $oidc->requestClientCredentialsToken()->access_token;
|
||||
$oidc_user = array(
|
||||
$oidc->authenticate();
|
||||
$_SESSION['access_token'] = $oidc->requestClientCredentialsToken()->access_token;
|
||||
$oidc_user = array(
|
||||
'sub' => $oidc->requestUserInfo('sub'),
|
||||
'username' => $oidc->requestUserInfo('preferred_username'),
|
||||
'given_name' => $oidc->requestUserInfo('given_name'),
|
||||
@@ -14,46 +14,41 @@
|
||||
'email' => $oidc->requestUserInfo('email'),
|
||||
);
|
||||
} catch (Jumbojett\OpenIDConnectClientException $e) {
|
||||
$alert = array("danger", "Error during OpenID Connect authentication: " . $e->getMessage());
|
||||
$alert = array("danger", "Error during OpenID Connect authentication: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Check if the user already exists
|
||||
try {
|
||||
$user_exist_sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid");
|
||||
$user_exist_sql->bindParam(':uuid', $oidc_user['sub']);
|
||||
$user_exist_sql->execute();
|
||||
} catch (PDOException $e) {
|
||||
$alert = array("danger", "Error during check for user record: " . $e->getMessage());
|
||||
}
|
||||
|
||||
if (empty($user_exist_sql)) {
|
||||
// User doesn't already exist
|
||||
try {
|
||||
$stmt = "INSERT INTO users (uuid, uid, given_name, family_name, email) VALUES (:sub, :username, :given, :family, :email)";
|
||||
$sql = $db->prepare($stmt);
|
||||
$sql->bindParam(':sub', $oidc_user['sub']);
|
||||
$sql->bindParam(':username', $oidc_user['username']);
|
||||
$sql->bindParam(':given', $oidc_user['given_name']);
|
||||
$sql->bindParam(':family', $oidc_user['family_name']);
|
||||
$sql->bindParam(':email', $oidc_user['email']);
|
||||
$sql->execute();
|
||||
} catch (Jumbojett\PDOException $e) {
|
||||
$alert = array("danger", "Error during creation of new user record: " . $e->getMessage());
|
||||
}
|
||||
if (user_exists($db, $oidc_user['sub']) == false) {
|
||||
// User doesn't already exist
|
||||
try {
|
||||
$stmt = "INSERT INTO users (uuid, uid, given_name, family_name, email) VALUES (:sub, :username, :given, :family, :email)";
|
||||
$sql = $db->prepare($stmt);
|
||||
$sql->bindParam(':sub', $oidc_user['sub']);
|
||||
$sql->bindParam(':username', $oidc_user['username']);
|
||||
$sql->bindParam(':given', $oidc_user['given_name']);
|
||||
$sql->bindParam(':family', $oidc_user['family_name']);
|
||||
$sql->bindParam(':email', $oidc_user['email']);
|
||||
$sql->execute();
|
||||
} catch (PDOException $e) {
|
||||
echo("Error during creation of new user record: " . $e->getMessage());
|
||||
die();
|
||||
$alert = array("danger", "Error during creation of new user record: " . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
// User already exists
|
||||
try {
|
||||
$stmt = "UPDATE users SET uid=:username, given_name=:given, family_name=:family, email=:email WHERE uuid=:sub";
|
||||
$sql = $db->prepare($stmt);
|
||||
$sql->bindParam(':sub', $oidc_user['sub']);
|
||||
$sql->bindParam(':username', $oidc_user['username']);
|
||||
$sql->bindParam(':given', $oidc_user['given_name']);
|
||||
$sql->bindParam(':family', $oidc_user['family_name']);
|
||||
$sql->bindParam(':email', $oidc_user['email']);
|
||||
$sql->execute();
|
||||
} catch (Jumbojett\PDOException $e) {
|
||||
$alert = array("danger", "Error during existing user record update: " . $e->getMessage());
|
||||
}
|
||||
// User already exists
|
||||
try {
|
||||
$stmt = "UPDATE users SET uid=:username, given_name=:given, family_name=:family, email=:email WHERE uuid=:sub";
|
||||
$sql = $db->prepare($stmt);
|
||||
$sql->bindParam(':sub', $oidc_user['sub']);
|
||||
$sql->bindParam(':username', $oidc_user['username']);
|
||||
$sql->bindParam(':given', $oidc_user['given_name']);
|
||||
$sql->bindParam(':family', $oidc_user['family_name']);
|
||||
$sql->bindParam(':email', $oidc_user['email']);
|
||||
$sql->execute();
|
||||
} catch (PDOException $e) {
|
||||
echo("Error during existing user record update: " . $e->getMessage());
|
||||
die();
|
||||
$alert = array("danger", "Error during existing user record update: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
oidc_set_vars($oidc_user['sub'], $oidc_user['username'], $oidc_user['given_name'], $oidc_user['family_name'], $oidc_user['email']);
|
||||
@@ -62,4 +57,3 @@
|
||||
$_SESSION['is_signed_in'] = "true";
|
||||
|
||||
header('Location: /');
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user