TwoFAccountDynamicRequest.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Api\v1\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Arr;
  5. use Illuminate\Support\Facades\Auth;
  6. class TwoFAccountDynamicRequest extends FormRequest
  7. {
  8. /**
  9. * Determine if the user is authorized to make this request.
  10. *
  11. * @return bool
  12. */
  13. public function authorize()
  14. {
  15. return Auth::check();
  16. }
  17. /**
  18. * Get the validation rules that apply to the request.
  19. *
  20. * @return array
  21. */
  22. public function rules()
  23. {
  24. $rules = Arr::has($this->validationData(), 'uri')
  25. ? (new TwoFAccountUriRequest)->rules()
  26. : (new TwoFAccountStoreRequest)->rules();
  27. return $rules;
  28. }
  29. /**
  30. * Prepare the data for validation.
  31. *
  32. * @codeCoverageIgnore
  33. *
  34. * @return void
  35. */
  36. protected function prepareForValidation()
  37. {
  38. $this->merge([
  39. 'otp_type' => strtolower($this->otp_type),
  40. 'algorithm' => strtolower($this->algorithm),
  41. ]);
  42. }
  43. }