TwoFAccountStoreRequest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Api\v1\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Facades\Auth;
  5. class TwoFAccountStoreRequest extends FormRequest
  6. {
  7. /**
  8. * Determine if the user is authorized to make this request.
  9. *
  10. * @return bool
  11. */
  12. public function authorize()
  13. {
  14. return Auth::check();
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array
  20. */
  21. public function rules()
  22. {
  23. return [
  24. 'service' => 'nullable|string|regex:/^[^:]+$/i',
  25. 'account' => 'required|string|regex:/^[^:]+$/i',
  26. 'icon' => 'nullable|string',
  27. 'otp_type' => 'required|string|in:totp,hotp,steamtotp',
  28. 'secret' => ['string', 'bail', new \App\Rules\IsBase32Encoded],
  29. 'digits' => 'nullable|integer|between:5,10',
  30. 'algorithm' => 'nullable|string|in:sha1,sha256,sha512,md5',
  31. 'period' => 'nullable|integer|min:1',
  32. 'counter' => 'nullable|integer|min:0',
  33. ];
  34. }
  35. /**
  36. * Prepare the data for validation.
  37. *
  38. * @codeCoverageIgnore
  39. *
  40. * @return void
  41. */
  42. protected function prepareForValidation()
  43. {
  44. $this->merge([
  45. 'otp_type' => strtolower($this->otp_type),
  46. 'algorithm' => strtolower($this->algorithm),
  47. ]);
  48. }
  49. }