TwoFAccountDynamicRequest.php 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Api\v1\Requests;
  3. use Illuminate\Support\Arr;
  4. use Illuminate\Foundation\Http\FormRequest;
  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. * @return void
  33. */
  34. protected function prepareForValidation()
  35. {
  36. $this->merge([
  37. 'otp_type' => strtolower($this->otp_type),
  38. 'algorithm' => strtolower($this->algorithm),
  39. ]);
  40. }
  41. }