mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-04-10 01:39:07 +02:00
Add Form Requests for TwoFAccounts validation
This commit is contained in:
parent
f7fcef77f1
commit
a2c67d1558
30
app/Http/Requests/TwoFAccountDeleteRequest.php
Normal file
30
app/Http/Requests/TwoFAccountDeleteRequest.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class TwoFAccountDeleteRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'ids' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
33
app/Http/Requests/TwoFAccountDynamicRequest.php
Normal file
33
app/Http/Requests/TwoFAccountDynamicRequest.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class TwoFAccountDynamicRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
$rules = Arr::has($this->validationData(), 'uri')
|
||||||
|
? (new TwoFAccountUriRequest)->rules()
|
||||||
|
: (new TwoFAccountStoreRequest)->rules();
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class TwoFAccountEditRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
|
|
||||||
// see https://github.com/google/google-authenticator/wiki/Key-Uri-Format
|
|
||||||
// for otpauth uri format validation
|
|
||||||
return [
|
|
||||||
'service' => 'required_without:uri|string',
|
|
||||||
'account' => 'required_without:uri|nullable|string|regex:/^[^:]+$/i',
|
|
||||||
'icon' => 'nullable|string',
|
|
||||||
'uri' => 'nullable|string|regex:/^otpauth:\/\/[h,t]otp\//i',
|
|
||||||
'otpType' => 'required_without:uri|in:totp,hotp',
|
|
||||||
'secret' => 'required_without:uri|string',
|
|
||||||
'digits' => 'nullable|integer|between:6,10',
|
|
||||||
'algorithm' => 'nullable|in:sha1,sha256,sha512,md5',
|
|
||||||
'period' => 'required_if:otpType,totp|nullable|integer|min:1',
|
|
||||||
'counter' => 'required_if:otpType,hotp|nullable|integer|min:0',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,18 +23,14 @@ public function authorize()
|
|||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
|
|
||||||
// see https://github.com/google/google-authenticator/wiki/Key-Uri-Format
|
|
||||||
// for otpauth uri format validation
|
|
||||||
return [
|
return [
|
||||||
'service' => 'required_without:uri|string',
|
'service' => 'nullable|string|regex:/^[^:]+$/i',
|
||||||
'account' => 'required_without:uri|nullable|string|regex:/^[^:]+$/i',
|
'account' => 'required|string|regex:/^[^:]+$/i',
|
||||||
'icon' => 'nullable|string',
|
'icon' => 'nullable|string',
|
||||||
'uri' => 'nullable|string|regex:/^otpauth:\/\/[h,t]otp\//i',
|
'otp_type' => 'required|string|in:totp,hotp',
|
||||||
'otpType' => 'required_without:uri|in:totp,hotp',
|
'secret' => ['string', 'bail', new \App\Rules\IsBase32Encoded],
|
||||||
'secret' => 'required_without:uri|string',
|
|
||||||
'digits' => 'nullable|integer|between:6,10',
|
'digits' => 'nullable|integer|between:6,10',
|
||||||
'algorithm' => 'nullable|in:sha1,sha256,sha512,md5',
|
'algorithm' => 'nullable|string|in:sha1,sha256,sha512,md5',
|
||||||
'period' => 'nullable|integer|min:1',
|
'period' => 'nullable|integer|min:1',
|
||||||
'counter' => 'nullable|integer|min:0',
|
'counter' => 'nullable|integer|min:0',
|
||||||
];
|
];
|
||||||
|
38
app/Http/Requests/TwoFAccountUpdateRequest.php
Normal file
38
app/Http/Requests/TwoFAccountUpdateRequest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class TwoFAccountUpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'service' => 'required|nullable|string|regex:/^[^:]+$/i',
|
||||||
|
'account' => 'required|string|regex:/^[^:]+$/i',
|
||||||
|
'icon' => 'required|nullable|string',
|
||||||
|
'otp_type' => 'required|string|in:totp,hotp',
|
||||||
|
'secret' => ['required', 'string', 'bail', new \App\Rules\IsBase32Encoded],
|
||||||
|
'digits' => 'required|integer|between:6,10',
|
||||||
|
'algorithm' => 'required|string|in:sha1,sha256,sha512,md5',
|
||||||
|
'period' => 'required_if:otp_type,totp|integer|min:1',
|
||||||
|
'counter' => 'required_if:otp_type,hotp|integer|min:0',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
30
app/Http/Requests/TwoFAccountUriRequest.php
Normal file
30
app/Http/Requests/TwoFAccountUriRequest.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class TwoFAccountUriRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'uri' => 'required|string|regex:/^otpauth:\/\/[h,t]otp\//i',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user