TwoFAccountUpdateRequest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Api\v1\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Facades\Auth;
  5. class TwoFAccountUpdateRequest 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' => 'present|nullable|string|regex:/^[^:]+$/i',
  25. 'account' => 'required|string|regex:/^[^:]+$/i',
  26. 'icon' => 'present|nullable|string',
  27. 'otp_type' => 'required|string|in:totp,hotp,steamtotp',
  28. 'secret' => ['present', 'string', 'bail', new \App\Rules\IsBase32Encoded],
  29. 'digits' => 'present|integer|between:5,10',
  30. 'algorithm' => 'present|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. }