StoreEmailCertificationRequest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Services\V3\SignUpService;
  4. use Closure;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. /**
  7. * `POST /v3/email-certifications` 的入参:给待注册的邮箱发验证码。
  8. */
  9. class StoreEmailCertificationRequest extends FormRequest
  10. {
  11. public function authorize(): bool
  12. {
  13. return true;
  14. }
  15. /**
  16. * @return array<string, array<int, mixed>>
  17. */
  18. public function rules(): array
  19. {
  20. return [
  21. // user_infos.email 是 varchar(256)
  22. 'email' => [
  23. 'required', 'email', 'max:256',
  24. function (string $attribute, mixed $value, Closure $fail): void {
  25. if (app(SignUpService::class)->emailRegistered((string) $value)) {
  26. $fail(__('messages.email_registered'));
  27. }
  28. },
  29. ],
  30. // 邮件语言,没有对应模板的回落 en,所以这里不限定取值
  31. 'lang' => ['sometimes', 'string', 'max:16'],
  32. ];
  33. }
  34. }