mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-02-02 11:39:19 +01:00
Refactor Rules to Laravel 10 format
This commit is contained in:
parent
dacb3d2e58
commit
1ad1b62caf
@ -2,46 +2,24 @@
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CaseInsensitiveEmailExists implements Rule
|
||||
class CaseInsensitiveEmailExists implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
* Run the validation rule.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$user = DB::table('users')
|
||||
->whereRaw('email = ?' . ('sqlite' === config('database.default') ? ' COLLATE NOCASE' : ''), [strtolower($value)])
|
||||
->first();
|
||||
->whereRaw('email = ?' . ('sqlite' === config('database.default') ? ' COLLATE NOCASE' : ''), [strtolower($value)])
|
||||
->first();
|
||||
|
||||
return ! $user ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return trans('validation.custom.email.exists');
|
||||
if (! $user) {
|
||||
$fail('validation.custom.email.exists')->translate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,46 +3,21 @@
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Helpers\Helpers;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use ParagonIE\ConstantTime\Base32;
|
||||
|
||||
class IsBase32Encoded implements Rule
|
||||
class IsBase32Encoded implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
* Run the validation rule.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
try {
|
||||
$secret = Base32::decodeUpper(Helpers::PadToBase32Format($value));
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
$fail('validation.custom.secret.isBase32Encoded')->translate();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return trans('validation.custom.secret.isBase32Encoded');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user