ldc-gen-game-web/app/Http/Requests/ParticipateRequest.php
Jérémy Munsch 9ee2123928
- composer require kwaadpepper/serial-int-caster
- add code parameters into config
- add code length parameter into settings
- add total possible codes to generate in generation page
- add GenerateRequest validation
- changed job ProcessUniqueCode to increase performances using mass insert and pagination
- changed singletoned Settings instance to increase performances
- Fix process export code put datetime in file name
- aded storage to gitignore file
- fixed export to guess export codes, also non recursive now
- changed refactorize a bit EnterCodeController::participate + add request
- Add request to export and generate codes requests
2022-01-07 19:03:25 +01:00

62 lines
2 KiB
PHP

<?php
namespace App\Http\Requests;
use App\Models\Codes;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Kwaadpepper\Serial\Exceptions\SerialCasterException;
class ParticipateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
$this->merge([
'code' => is_string($this->code) ? Str::upper($this->code) : $this->code,
'accept_rules' => $this->accept_rules ? true : false
]);
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'accept_rules' => [
'required', 'boolean',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
if (!$value) {
$fail('Pour participer, vous devez accepter le règlement du jeu.');
}
}
],
'code' => [
'required', 'string',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
try {
$int = Codes::serialToInt($value);
if (!Codes::whereId(Codes::serialToInt($value))->exists()) {
throw new SerialCasterException();
}
} catch (SerialCasterException $e) {
dd($e);
Log::debug($e->getMessage(), $e->getTrace());
$fail('Code incorrect, veuillez réessayer.');
}
}
]
];
}
}