Restyled by php-cs-fixer

This commit is contained in:
Restyled.io
2020-08-17 14:44:58 +00:00
parent 9e8b0c7769
commit 7d38a80071
2 changed files with 41 additions and 44 deletions

View File

@@ -8,15 +8,14 @@
function user_exists($db, $uuid) function user_exists($db, $uuid)
{ {
try { try {
$sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid"); $sql = $db->prepare("SELECT uuid FROM users WHERE uuid=:uuid");
$sql->bindParam(':uuid', $uuid); $sql->bindParam(':uuid', $uuid);
$sql->execute(); $sql->execute();
} 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 (empty($sql)) if (empty($sql)) {
{
return false; return false;
} else { } else {
return true; return true;

View File

@@ -4,9 +4,9 @@
// Perform the OIDC authentication // Perform the OIDC authentication
try { try {
$oidc->authenticate(); $oidc->authenticate();
$_SESSION['access_token'] = $oidc->requestClientCredentialsToken()->access_token; $_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'),
'given_name' => $oidc->requestUserInfo('given_name'), 'given_name' => $oidc->requestUserInfo('given_name'),
@@ -14,42 +14,41 @@
'email' => $oidc->requestUserInfo('email'), 'email' => $oidc->requestUserInfo('email'),
); );
} catch (Jumbojett\OpenIDConnectClientException $e) { } catch (Jumbojett\OpenIDConnectClientException $e) {
$alert = array("danger", "Error during OpenID Connect authentication: " . $e->getMessage()); $alert = array("danger", "Error during OpenID Connect authentication: " . $e->getMessage());
} }
if (!user_exists($db, $uuid)) if (!user_exists($db, $uuid)) {
{ // 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)"; $sql = $db->prepare($stmt);
$sql = $db->prepare($stmt); $sql->bindParam(':sub', $oidc_user['sub']);
$sql->bindParam(':sub', $oidc_user['sub']); $sql->bindParam(':username', $oidc_user['username']);
$sql->bindParam(':username', $oidc_user['username']); $sql->bindParam(':given', $oidc_user['given_name']);
$sql->bindParam(':given', $oidc_user['given_name']); $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 (Jumbojett\PDOException $e) {
} catch (Jumbojett\PDOException $e) { echo("Error during creation of new user record: " . $e->getMessage());
echo("Error during creation of new user record: " . $e->getMessage()); die();
die(); $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 { } else {
// User already exists // User already exists
try { try {
$stmt = "UPDATE users SET uid=:username, given_name=:given, family_name=:family, email=:email WHERE uuid=:sub"; $stmt = "UPDATE users SET uid=:username, given_name=:given, family_name=:family, email=:email WHERE uuid=:sub";
$sql = $db->prepare($stmt); $sql = $db->prepare($stmt);
$sql->bindParam(':sub', $oidc_user['sub']); $sql->bindParam(':sub', $oidc_user['sub']);
$sql->bindParam(':username', $oidc_user['username']); $sql->bindParam(':username', $oidc_user['username']);
$sql->bindParam(':given', $oidc_user['given_name']); $sql->bindParam(':given', $oidc_user['given_name']);
$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 (Jumbojett\PDOException $e) { } catch (Jumbojett\PDOException $e) {
echo("Error during existing user record update: " . $e->getMessage()); echo("Error during existing user record update: " . $e->getMessage());
die(); die();
$alert = array("danger", "Error during existing user record update: " . $e->getMessage()); $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']);
@@ -58,4 +57,3 @@
$_SESSION['is_signed_in'] = "true"; $_SESSION['is_signed_in'] = "true";
header('Location: /'); header('Location: /');
?>