EmailController.php 2.7 KB

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