Skip to content

Commit

Permalink
Improve _sha256 field handling
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed May 17, 2022
1 parent feb6f2b commit 8b1eeda
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Core/LTIX.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php


namespace Tsugi\Core;

use \Tsugi\OAuth\TrivialOAuthDataStore;
Expand Down Expand Up @@ -1369,7 +1370,7 @@ public static function loadAllData($p, $profile_table, $post) {
$sql .= "\nWHERE (k.deploy_key = :deployment_id OR k.deploy_key IS NULL)
AND (
(i.issuer_sha256 = :issuer_sha256 AND i.issuer_client = :issuer_client)
OR ( lms_issuer_sha256 = :issuer_sha256 AND lms_client = :issuer_client )
OR ( (lms_issuer_sha256 IS NULL OR lms_issuer_sha256 = :issuer_sha256 ) AND lms_client = :issuer_client )
)
";
} else {
Expand Down
22 changes: 21 additions & 1 deletion src/UI/CrudForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public static function handleInsert($tablename, $fields) {
// Set the sha256 value if it is not there
if ( strpos($field, "_sha256") !== false && ! isset($_POST[$field])) {
$key = str_replace("_sha256", "_key", $field);
$key2 = str_replace("_sha256", "", $field);
// Allow nulls
if ( array_key_exists($key, $_POST)) {
// All good
} else if ( array_key_exists($key2, $_POST)) {
$key = $key2;
} else {
continue;
}

// Nulls allowed
if ( !array_key_exists($key, $_POST) ) {
$_SESSION['error'] = "Missing POST field: ".$key;
Expand Down Expand Up @@ -352,10 +362,20 @@ public static function handleUpdate($tablename, $fields, $where_clause=false,
}

// Update the sha256 value if we have a corresponding _key value
// xyz => xyz_sha256
// xyz_key => xyz_sha256
if ( strpos($field, "_sha256") !== false && ! isset($_POST[$field])) {
$key = str_replace("_sha256", "_key", $field);
$key2 = str_replace("_sha256", "", $field);
// Allow nulls
if ( ! array_key_exists($key, $_POST) ) continue;
if ( array_key_exists($key, $_POST)) {
// All good
} else if ( array_key_exists($key2, $_POST)) {
$key = $key2;
} else {
continue;
}

if ( $_POST[$key] === null ) {
$value = null;
} else {
Expand Down

0 comments on commit 8b1eeda

Please sign in to comment.