CommController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Controllers\Passport;
  3. use App\Http\Requests\Passport\CommSendEmailVerify;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Http\Exceptions\HttpResponseException;
  7. use Illuminate\Support\Facades\Mail;
  8. use Illuminate\Support\Facades\Redis;
  9. use App\Jobs\SendEmail;
  10. class CommController extends Controller
  11. {
  12. public function config () {
  13. return response([
  14. 'data' => [
  15. 'isEmailVerify' => (int)config('v2board.email_verify', 0) ? 1 : 0,
  16. 'isInviteForce' => (int)config('v2board.invite_force', 0) ? 1 : 0
  17. ]
  18. ]);
  19. }
  20. private function isEmailVerify () {
  21. return response([
  22. 'data' => (int)config('v2board.email_verify', 0) ? 1 : 0
  23. ]);
  24. }
  25. public function sendEmailVerify (CommSendEmailVerify $request) {
  26. $email = $request->input('email');
  27. $redisKey = 'sendEmailVerify:' . $email;
  28. if (Redis::get($redisKey)) {
  29. abort(500, '验证码已发送,请过一会在请求');
  30. }
  31. $code = rand(100000, 999999);
  32. $subject = config('v2board.app_name', 'V2Board') . '邮箱验证码';
  33. $this->dispatch(new SendEmail([
  34. 'email' => $email,
  35. 'template_name' => 'mail.sendEmailVerify',
  36. 'template_value' => [
  37. 'code' => $code,
  38. 'name' => config('v2board.app_name', 'V2Board')
  39. ],
  40. 'subject' => $subject
  41. ]));
  42. Redis::set($redisKey, $code);
  43. Redis::expire($redisKey, 600);
  44. return response([
  45. 'data' => true
  46. ]);
  47. }
  48. }