EmailController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\Jkq\Auth;
  3. use App\Http\Controllers\Jkq\JkqBaseController;
  4. use App\Services\Auth\AuthService;
  5. use App\Services\Common\EmailService;
  6. use App\Services\Common\TaskService;
  7. use App\Services\Company\CompanyService;
  8. use App\Services\Organization\OrganizationService;
  9. use App\Services\Person\MemberInfoService;
  10. class EmailController extends JkqBaseController
  11. {
  12. /**
  13. * @var EmailService
  14. */
  15. protected $emailService;
  16. /**
  17. * @var CompanyService
  18. */
  19. private $companyService;
  20. private $memberInfoService;
  21. /**
  22. * @var AuthService
  23. */
  24. private $authService;
  25. private $taskService;
  26. private $organizationService;
  27. /**
  28. * EmailController constructor.
  29. * @param EmailService $emailService
  30. * @param CompanyService $companyService
  31. * @param MemberInfoService $memberInfoService
  32. * @param AuthService $authService
  33. * @param TaskService $taskService
  34. */
  35. public function __construct(EmailService $emailService, TaskService $taskService, CompanyService $companyService, MemberInfoService $memberInfoService, AuthService $authService, OrganizationService $organizationService)
  36. {
  37. $this->emailService = $emailService;
  38. $this->companyService = $companyService;
  39. $this->memberInfoService = $memberInfoService;
  40. $this->authService = $authService;
  41. $this->taskService = $taskService;
  42. $this->organizationService = $organizationService;
  43. }
  44. public function checkEmail($token, $tag = 'none')
  45. {
  46. $message = $this->emailService->checkAuthEmail($token);
  47. if (is_null($message)) {
  48. // return "地址已失效";//token不对
  49. return $this->showMessage("地址已失效", route('jkq.home'), true, "首页");
  50. }
  51. //token验证是对的
  52. if ($message['alias']==EmailService::TEMPLATE_VALIDATION) {
  53. //验证邮箱逻辑
  54. if ($tag == 'company') {
  55. if ($this->companyService->verifyEmail($message['email'])) {
  56. $this->taskService->doTask(23);
  57. return $this->showMessage("邮箱认证成功!", route('jkq.home'), false, "首页");
  58. }
  59. }
  60. if ($tag == 'organization') {
  61. if ($this->organizationService->verifyEmail($message['email'])) {
  62. //$this->taskService->doTask(23);
  63. return $this->showMessage("邮箱认证成功!", route('jkq.home'), false, "首页");
  64. }
  65. }
  66. if ($tag == 'personal') {
  67. if ($this->memberInfoService->verifyEmail($message['email'])) {
  68. return $this->showMessage("邮箱认证成功!", route('jkq.home'), false, "首页");
  69. }
  70. }
  71. }
  72. if ($message['alias']==EmailService::TEMPLATE_PASSWORD_RESET) {
  73. //重置密码逻辑
  74. $token=$this->authService->getTokenByEmail($message['email']);
  75. return view('app.auth.password_reset', ['token'=>$token]);
  76. }
  77. return $this->showMessage("地址已失效", route('jkq.home'), true, "首页");
  78. }
  79. }