Merge Main with feature/71 #81

Merged
MrLyallCSIT merged 4 commits from main into feature/71 2020-08-13 19:18:36 +00:00
3 changed files with 22 additions and 22 deletions

View File

@@ -10,6 +10,6 @@ jobs:
steps: steps:
- uses: alex-page/github-project-automation-plus@v0.2.4 - uses: alex-page/github-project-automation-plus@v0.2.4
with: with:
project: FHeD v1.0 project: v1.0
column: In Progress column: In progress
repo-token: ${{ secrets.AUTO_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -5,6 +5,7 @@
// Perform the OIDC authentication // Perform the OIDC authentication
try { try {
$oidc->authenticate(); $oidc->authenticate();
$_SESSION['access_token'] = $oidc->requestClientCredentialsToken()->access_token;
$oidc_user = array( $oidc_user = array(
'sub' => $oidc->requestUserInfo('sub'), 'sub' => $oidc->requestUserInfo('sub'),
'username' => $oidc->requestUserInfo('preferred_username'), 'username' => $oidc->requestUserInfo('preferred_username'),
@@ -21,26 +22,11 @@
$user_exist_sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid"); $user_exist_sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid");
$user_exist_sql->bindParam(':uuid', $oidc_user['sub']); $user_exist_sql->bindParam(':uuid', $oidc_user['sub']);
$user_exist_sql->execute(); $user_exist_sql->execute();
$result = $user_exist_sql->setFetchMode(PDO::FETCH_ASSOC); // If user doesn't exist, $result will be null
} catch (PDOException $e) { } catch (PDOException $e) {
$alert = array("danger", "Error during check for user record: " . $e->getMessage()); $alert = array("danger", "Error during check for user record: " . $e->getMessage());
} }
if ($result != null) { if (empty($user_exist_sql)) {
// 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) {
$alert = array("danger", "Error during existing user record update: " . $e->getMessage());
}
} else {
// User doesn't already exist // User doesn't already exist
try { try {
$stmt = "INSERT INTO users (uuid, uid, given_name, family_name, email) VALUES (:sub, :username, :given, :family, :email)"; $stmt = "INSERT INTO users (uuid, uid, given_name, family_name, email) VALUES (:sub, :username, :given, :family, :email)";
@@ -51,9 +37,23 @@
$sql->bindParam(':family', $oidc_user['family_name']); $sql->bindParam(':family', $oidc_user['family_name']);
$sql->bindParam(':email', $oidc_user['email']); $sql->bindParam(':email', $oidc_user['email']);
$sql->execute(); $sql->execute();
} catch (PDOException $e) { } catch (Jumbojett\PDOException $e) {
$alert = array("danger", "Error during creation of new user record: " . $e->getMessage()); $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());
}
} }
oidc_set_vars($oidc_user['sub'], $oidc_user['username'], $oidc_user['given_name'], $oidc_user['family_name'], $oidc_user['email']); oidc_set_vars($oidc_user['sub'], $oidc_user['username'], $oidc_user['given_name'], $oidc_user['family_name'], $oidc_user['email']);

View File

@@ -2,7 +2,7 @@
$PAGE_NAME = "Logging out..."; $PAGE_NAME = "Logging out...";
require_once __DIR__ . "/../../includes/prereqs.php"; require_once __DIR__ . "/../../includes/prereqs.php";
$access_token = $_SESSION['access_token'];
session_destroy(); session_destroy();
$oidc->signOut($access_token, $_ENV['APP_URL']);
header('Location: /');
?> ?>