Skip to content

Commit

Permalink
temporary decrypt, almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerrlongg committed Feb 20, 2024
1 parent 26728a8 commit d67ff54
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/Providers/ValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Department;
use App\Models\Setting;
use DB;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rule;
Expand Down Expand Up @@ -300,13 +301,22 @@ public function boot()
// This is only used in Models/CustomFieldset.php - it does automatic validation for checkboxes by making sure
// that the submitted values actually exist in the options.
Validator::extend('checkboxes', function ($attribute, $value, $parameters, $validator){
$options = CustomField::where('db_column', $attribute)->first()->formatFieldValuesAsArray();
$field = CustomField::where('db_column', $attribute)->first();
$options = $field->formatFieldValuesAsArray();

// temporarily decrypt for validation
if($field->field_encrypted) {
$value = Crypt::decrypt($value);
}
dump(is_array($value));

if(is_array($value)) {
$invalid = array_diff($value, $options);
if(count($invalid) > 0) {
return false;
}
}

// for legacy, allows users to submit a comma separated string of options
elseif(!is_array($value)) {
$exploded = array_map('trim', explode(',', $value));
Expand All @@ -315,6 +325,7 @@ public function boot()
return false;
}
}

return true;
});
}
Expand Down

0 comments on commit d67ff54

Please sign in to comment.