TwoFAccountStoreRequest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. * @return void
  39. */
  40. protected function prepareForValidation()
  41. {
  42. $this->merge([
  43. 'otp_type' => strtolower($this->otp_type),
  44. 'algorithm' => strtolower($this->algorithm),
  45. ]);
  46. }
  47. }