This commit is contained in:
James Cole
2018-02-11 15:27:28 +01:00
parent dcf549261c
commit ef338e2515

View File

@@ -65,7 +65,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validate2faCode($attribute, $value): bool { public function validate2faCode($attribute, $value): bool
{
if (!is_string($value) || null === $value || 6 != strlen($value)) { if (!is_string($value) || null === $value || 6 != strlen($value)) {
return false; return false;
} }
@@ -84,7 +85,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateBelongsToUser($attribute, $value, $parameters): bool { public function validateBelongsToUser($attribute, $value, $parameters): bool
{
$field = $parameters[1] ?? 'id'; $field = $parameters[1] ?? 'id';
if (0 === intval($value)) { if (0 === intval($value)) {
@@ -106,7 +108,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateBic($attribute, $value): bool { public function validateBic($attribute, $value): bool
{
$regex = '/^[a-z]{6}[0-9a-z]{2}([0-9a-z]{3})?\z/i'; $regex = '/^[a-z]{6}[0-9a-z]{2}([0-9a-z]{3})?\z/i';
$result = preg_match($regex, $value); $result = preg_match($regex, $value);
if (false === $result) { if (false === $result) {
@@ -127,7 +130,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateIban($attribute, $value): bool { public function validateIban($attribute, $value): bool
{
if (!is_string($value) || null === $value || strlen($value) < 6) { if (!is_string($value) || null === $value || strlen($value) < 6) {
return false; return false;
} }
@@ -206,7 +210,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateMore($attribute, $value, $parameters): bool { public function validateMore($attribute, $value, $parameters): bool
{
$compare = $parameters[0] ?? '0'; $compare = $parameters[0] ?? '0';
return bccomp($value, $compare) > 0; return bccomp($value, $compare) > 0;
@@ -221,7 +226,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateMustExist($attribute, $value, $parameters): bool { public function validateMustExist($attribute, $value, $parameters): bool
{
$field = $parameters[1] ?? 'id'; $field = $parameters[1] ?? 'id';
if (0 === intval($value)) { if (0 === intval($value)) {
@@ -329,7 +335,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateSecurePassword($attribute, $value): bool { public function validateSecurePassword($attribute, $value): bool
{
$verify = false; $verify = false;
if (isset($this->data['verify_password'])) { if (isset($this->data['verify_password'])) {
$verify = 1 === intval($this->data['verify_password']); $verify = 1 === intval($this->data['verify_password']);
@@ -353,7 +360,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateUniqueAccountForUser($attribute, $value, $parameters): bool { public function validateUniqueAccountForUser($attribute, $value, $parameters): bool
{
// 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()) {
return $this->validateAccountAnonymously(); return $this->validateAccountAnonymously();
@@ -382,10 +390,12 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateUniqueAccountNumberForUser($attribute, $value): bool { public function validateUniqueAccountNumberForUser($attribute, $value): bool
{
$accountId = $this->data['id'] ?? 0; $accountId = $this->data['id'] ?? 0;
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->whereNull('accounts.deleted_at')
->where('accounts.user_id', auth()->user()->id) ->where('accounts.user_id', auth()->user()->id)
->where('account_meta.name', 'accountNumber'); ->where('account_meta.name', 'accountNumber');
@@ -461,7 +471,8 @@ class FireflyValidator extends Validator
* *
* @return bool * @return bool
*/ */
public function validateUniquePiggyBankForUser($attribute, $value, $parameters): bool { public function validateUniquePiggyBankForUser($attribute, $value, $parameters): bool
{
$exclude = $parameters[0] ?? null; $exclude = $parameters[0] ?? null;
$query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at') $query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id); ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id);