diff --git a/.github/workflows/assigned-issues-inprogress.yml b/.github/workflows/assigned-issues-inprogress.yml index defa967..67de8d7 100644 --- a/.github/workflows/assigned-issues-inprogress.yml +++ b/.github/workflows/assigned-issues-inprogress.yml @@ -10,6 +10,6 @@ jobs: steps: - uses: alex-page/github-project-automation-plus@v0.2.4 with: - project: FHeD v1.0 - column: In Progress - repo-token: ${{ secrets.AUTO_TOKEN }} + project: v1.0 + column: In progress + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/app/public/actions/login.php b/app/public/actions/login.php index bdfe7fe..38fdcc1 100644 --- a/app/public/actions/login.php +++ b/app/public/actions/login.php @@ -5,6 +5,7 @@ // Perform the OIDC authentication try { $oidc->authenticate(); + $_SESSION['access_token'] = $oidc->requestClientCredentialsToken()->access_token; $oidc_user = array( 'sub' => $oidc->requestUserInfo('sub'), 'username' => $oidc->requestUserInfo('preferred_username'), @@ -21,26 +22,11 @@ $user_exist_sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid"); $user_exist_sql->bindParam(':uuid', $oidc_user['sub']); $user_exist_sql->execute(); - $result = $user_exist_sql->setFetchMode(PDO::FETCH_ASSOC); // If user doesn't exist, $result will be null } catch (PDOException $e) { $alert = array("danger", "Error during check for user record: " . $e->getMessage()); } - if ($result != null) { - // 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 { + 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)"; @@ -51,9 +37,23 @@ $sql->bindParam(':family', $oidc_user['family_name']); $sql->bindParam(':email', $oidc_user['email']); $sql->execute(); - } catch (PDOException $e) { + } catch (Jumbojett\PDOException $e) { $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']); diff --git a/app/public/actions/logout.php b/app/public/actions/logout.php index 6bca8f6..8bbceb7 100644 --- a/app/public/actions/logout.php +++ b/app/public/actions/logout.php @@ -2,7 +2,7 @@ $PAGE_NAME = "Logging out..."; require_once __DIR__ . "/../../includes/prereqs.php"; + $access_token = $_SESSION['access_token']; session_destroy(); - - header('Location: /'); + $oidc->signOut($access_token, $_ENV['APP_URL']); ?>