2021-09-07 23:10:17 +02:00
|
|
|
<?php
|
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
namespace App\Api\v1\Requests;
|
2021-09-07 23:10:17 +02:00
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2021-11-13 13:36:34 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2021-09-07 23:10:17 +02:00
|
|
|
|
|
|
|
class TwoFAccountStoreRequest extends FormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
2021-11-13 13:36:34 +01:00
|
|
|
return Auth::check();
|
2021-09-07 23:10:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
2022-11-22 15:15:52 +01:00
|
|
|
'service' => 'nullable|string|regex:/^[^:]+$/i',
|
|
|
|
'account' => 'required|string|regex:/^[^:]+$/i',
|
|
|
|
'icon' => 'nullable|string',
|
2024-08-06 11:21:08 +02:00
|
|
|
'group_id' => 'sometimes|nullable|integer|min:0',
|
2022-11-22 15:15:52 +01:00
|
|
|
'otp_type' => 'required|string|in:totp,hotp,steamtotp',
|
|
|
|
'secret' => ['string', 'bail', new \App\Rules\IsBase32Encoded],
|
|
|
|
'digits' => 'nullable|integer|between:5,10',
|
2021-09-17 23:48:30 +02:00
|
|
|
'algorithm' => 'nullable|string|in:sha1,sha256,sha512,md5',
|
2022-11-22 15:15:52 +01:00
|
|
|
'period' => 'nullable|integer|min:1',
|
|
|
|
'counter' => 'nullable|integer|min:0',
|
2021-09-07 23:10:17 +02:00
|
|
|
];
|
|
|
|
}
|
2022-10-10 12:55:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the data for validation.
|
|
|
|
*
|
2022-12-09 10:52:17 +01:00
|
|
|
* @codeCoverageIgnore
|
|
|
|
*
|
2022-10-10 12:55:59 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function prepareForValidation()
|
|
|
|
{
|
|
|
|
$this->merge([
|
2022-11-22 15:15:52 +01:00
|
|
|
'otp_type' => strtolower($this->otp_type),
|
2022-10-10 12:55:59 +02:00
|
|
|
'algorithm' => strtolower($this->algorithm),
|
|
|
|
]);
|
|
|
|
}
|
2021-09-07 23:10:17 +02:00
|
|
|
}
|