mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-23 15:40:32 -06:00
Fix #7549
This commit is contained in:
parent
f711fcfd52
commit
e6daaa5b6d
@ -105,8 +105,8 @@ class StoreRequest extends FormRequest
|
||||
$validator->after(
|
||||
static function (Validator $validator) {
|
||||
$data = $validator->getData();
|
||||
$min = $data['amount_min'] ?? '0';
|
||||
$max = $data['amount_max'] ?? '0';
|
||||
$min = (string) ($data['amount_min'] ?? '0');
|
||||
$max = (string) ($data['amount_max'] ?? '0');
|
||||
|
||||
if (1 === bccomp($min, $max)) {
|
||||
$validator->errors()->add('amount_min', (string)trans('validation.amount_min_over_max'));
|
||||
|
@ -114,6 +114,7 @@ class AccountFactory
|
||||
*/
|
||||
public function create(array $data): Account
|
||||
{
|
||||
Log::debug('Now in AccountFactory::create()');
|
||||
$type = $this->getAccountType($data);
|
||||
$data['iban'] = $this->filterIban($data['iban'] ?? null);
|
||||
|
||||
@ -174,6 +175,7 @@ class AccountFactory
|
||||
*/
|
||||
public function find(string $accountName, string $accountType): ?Account
|
||||
{
|
||||
Log::debug(sprintf('Now in AccountFactory::find("%s", "%s")', $accountName, $accountType));
|
||||
$type = AccountType::whereType($accountType)->first();
|
||||
|
||||
return $this->user->accounts()->where('account_type_id', $type->id)->where('name', $accountName)->first();
|
||||
|
@ -42,8 +42,8 @@ use FireflyIII\TransactionRules\Triggers\TriggerInterface;
|
||||
use FireflyIII\User;
|
||||
use Google2FA;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\Validator;
|
||||
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException;
|
||||
use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;
|
||||
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;
|
||||
@ -67,7 +67,7 @@ class FireflyValidator extends Validator
|
||||
*/
|
||||
public function validate2faCode($attribute, $value): bool
|
||||
{
|
||||
if (null === $value || !is_string($value) || 6 !== strlen($value)) {
|
||||
if (!is_string($value) || 6 !== strlen($value)) {
|
||||
return false;
|
||||
}
|
||||
$user = auth()->user();
|
||||
@ -475,26 +475,33 @@ class FireflyValidator extends Validator
|
||||
{
|
||||
// because a user does not have to be logged in (tests and what-not).
|
||||
if (!auth()->check()) {
|
||||
Log::debug('validateUniqueAccountForUser::anon');
|
||||
return $this->validateAccountAnonymously();
|
||||
}
|
||||
if (array_key_exists('objectType', $this->data)) {
|
||||
Log::debug('validateUniqueAccountForUser::typeString');
|
||||
return $this->validateByAccountTypeString($value, $parameters, $this->data['objectType']);
|
||||
}
|
||||
if (array_key_exists('type', $this->data)) {
|
||||
Log::debug('validateUniqueAccountForUser::typeString');
|
||||
return $this->validateByAccountTypeString($value, $parameters, (string)$this->data['type']);
|
||||
}
|
||||
if (array_key_exists('account_type_id', $this->data)) {
|
||||
Log::debug('validateUniqueAccountForUser::typeId');
|
||||
return $this->validateByAccountTypeId($value, $parameters);
|
||||
}
|
||||
$parameterId = $parameters[0] ?? null;
|
||||
if (null !== $parameterId) {
|
||||
Log::debug('validateUniqueAccountForUser::paramId');
|
||||
return $this->validateByParameterId((int)$parameterId, $value);
|
||||
}
|
||||
if (array_key_exists('id', $this->data)) {
|
||||
Log::debug('validateUniqueAccountForUser::accountId');
|
||||
return $this->validateByAccountId($value);
|
||||
}
|
||||
|
||||
// without type, just try to validate the name.
|
||||
Log::debug('validateUniqueAccountForUser::accountName');
|
||||
return $this->validateByAccountName($value);
|
||||
}
|
||||
|
||||
@ -511,12 +518,8 @@ class FireflyValidator extends Validator
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$value = $this->data['name'];
|
||||
|
||||
$set = $user->accounts()->where('account_type_id', $type->id)->get();
|
||||
$result = $set->first(
|
||||
function (Account $account) use ($value) {
|
||||
return $account->name === $value;
|
||||
}
|
||||
);
|
||||
/** @var Account|null $result */
|
||||
$result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first();
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
@ -540,14 +543,10 @@ class FireflyValidator extends Validator
|
||||
$accountTypes = AccountType::whereIn('type', $search)->get();
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
$accountTypeIds = $accountTypes->pluck('id')->toArray();
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)->get();
|
||||
$result = $set->first(
|
||||
function (Account $account) use ($value) {
|
||||
return $account->name === $value;
|
||||
}
|
||||
);
|
||||
|
||||
/** @var Account|null $result */
|
||||
$result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
@ -562,14 +561,10 @@ class FireflyValidator extends Validator
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
|
||||
|
||||
$result = $set->first(
|
||||
function (Account $account) use ($value) {
|
||||
return $account->name === $value;
|
||||
}
|
||||
);
|
||||
/** @var Account|null $result */
|
||||
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
@ -795,18 +790,15 @@ class FireflyValidator extends Validator
|
||||
$exclude = (int)$data['id'];
|
||||
}
|
||||
// get entries from table
|
||||
$set = DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
||||
->where('id', '!=', $exclude)->get([$field]);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$fieldValue = $entry->$field;
|
||||
|
||||
if ($fieldValue === $value) {
|
||||
return false;
|
||||
}
|
||||
$result = DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
||||
->where('id', '!=', $exclude)
|
||||
->where($field, $value)
|
||||
->first([$field]);
|
||||
if (null === $result) {
|
||||
return true; // not found, so true.
|
||||
}
|
||||
|
||||
return true;
|
||||
// found, so not unique.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user