diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index 71be28e8a3a..d6bd7a1bef9 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -2,6 +2,8 @@ namespace App\Models; +use App\Rules\AlphaEncrypted; +use App\Rules\NumericEncrypted; use Gate; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -95,6 +97,19 @@ public function validation_rules() array_push($rule, $field->attributes['format']); $rules[$field->db_column_name()] = $rule; + + // these are to replace the standard 'numeric' and 'alpha' rules if the custom field is also encrypted. + // the values need to be decrypted first, because encrypted strings are alphanumeric + if ($field->format === 'NUMERIC' && $field->field_encrypted) { + $numericKey = array_search('numeric', $rules[$field->db_column_name()]); + $rules[$field->db_column_name()][$numericKey] = new NumericEncrypted; + } + + if ($field->format === 'ALPHA' && $field->field_encrypted) { + $alphaKey = array_search('alpha', $rules[$field->db_column_name()]); + $rules[$field->db_column_name()][$alphaKey] = new AlphaEncrypted; + } + // add not_array to rules for all fields but checkboxes if ($field->element != 'checkbox') { $rules[$field->db_column_name()][] = 'not_array'; diff --git a/app/Rules/AlphaEncrypted.php b/app/Rules/AlphaEncrypted.php new file mode 100644 index 00000000000..b39a5fedba4 --- /dev/null +++ b/app/Rules/AlphaEncrypted.php @@ -0,0 +1,29 @@ + $attributeName])); + } + } catch (\Exception $e) { + report($e); + $fail(trans('general.something_went_wrong')); + } + } +} diff --git a/app/Rules/NumericEncrypted.php b/app/Rules/NumericEncrypted.php new file mode 100644 index 00000000000..4121ce5178e --- /dev/null +++ b/app/Rules/NumericEncrypted.php @@ -0,0 +1,31 @@ + $attributeName])); + } + } catch (\Exception $e) { + report($e->getMessage()); + $fail(trans('general.something_went_wrong')); + } + } +} diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 7d7840eb426..d054c8b4397 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -187,6 +187,8 @@ 'custom' => [ 'alpha_space' => 'The :attribute field contains a character that is not allowed.', + 'alpha_encrypted' => 'The :attribute field should be alphabetic characters.', + 'numeric_encrypted' => 'The :attribute field should be numeric characters.', 'email_array' => 'One or more email addresses is invalid.', 'hashed_pass' => 'Your current password is incorrect', 'dumbpwd' => 'That password is too common.',