Skip to content

Commit

Permalink
internal(validation): make rule to see if value matches current password
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Oct 9, 2023
1 parent cb56c43 commit 1391218
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/Validation/EnumerationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ public function may_allow_exchange_action(
$debit_account_id = dot_array_search($parameters[0], $data);
$credit_account_id = dot_array_search($parameters[1], $data);

return $this->mustBeDifferentCurrecies($debit_account_id, $credit_account_id);
return $this->mustBeDifferentCurrencies($debit_account_id, $credit_account_id);
}

return true;
}

private function mustBeDifferentCurrecies(int $debit_account_id, int $credit_account_id): bool {
private function mustBeDifferentCurrencies(
int $debit_account_id,
int $credit_account_id
): bool {
$accounts = model(AccountModel::class)
->whereIn("id", [ $debit_account_id, $credit_account_id ])
->find();
Expand Down
14 changes: 14 additions & 0 deletions app/Validation/SimilarityRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public function must_be_same_for_financial_entry(
return $this->mayAllowForDualCurrency($modifier_id);
}

public function must_be_same_as_password_of_current_user(
$given_password,
string $parameters,
array $data,
?string &$error = null
): bool {
helper("array");

$current_user = auth()->user();
$password_service = service("passwords");

return $passwords->verify($given_password, $current_user->password_hash);
}

private function mayAllowForDualCurrency(int $modifier_id): bool {
$modifier = model(ModifierModel::class)->find($modifier_id);
$accounts = model(AccountModel::class)
Expand Down

0 comments on commit 1391218

Please sign in to comment.