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