SignupController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use App\Services\Msg\MailTemplateService;
  6. use Illuminate\Support\Facades\Validator;
  7. use App\Events\UserCreated;
  8. class SignupController extends Controller
  9. {
  10. private $callApiService;
  11. private $mailTemplateService;
  12. public function __construct(CallApiService $callApiService, MailTemplateService $mailTemplateService)
  13. {
  14. $this->callApiService = $callApiService;
  15. $this->mailTemplateService = $mailTemplateService;
  16. }
  17. public function index()
  18. {
  19. $passwdPolicy = setupPasswdPolicy('member');
  20. $smsCert = session('smsCert');
  21. // if (empty($smsCert) || empty($smsCert['code'])) {
  22. // notify()->error('잘못된 접근입니다', 'Error', 'bottomRight');
  23. // return redirect()->route('member-signup-verify.index');
  24. // }
  25. //
  26. // if ($smsCert['code'] !== 200) {
  27. // notify()->error('인증실패', 'Error', 'bottomRight');
  28. // return redirect()->route('member-signup-verify.index');
  29. // }
  30. //
  31. // if (date('YmdHis') - $smsCert['date'] > 500) {
  32. // session()->forget('smsCert');
  33. // notify()->error('인증 시간이 만료되었습니다', 'Error', 'bottomRight');
  34. // return redirect()->route('member-signup-verify.index');
  35. // }
  36. return view('views.auth.member-signup', [
  37. 'passwdPolicy' => $passwdPolicy,
  38. ]);
  39. }
  40. public function store()
  41. {
  42. $passwdPolicy = setupPasswdPolicy('member');
  43. if ($this->callApiService->verifyApiError($passwdPolicy)) {
  44. notify()->error($passwdPolicy['body'], 'Error', 'bottomRight');
  45. return redirect()->back();
  46. }
  47. $passwdRules = makePasswdRules($passwdPolicy);
  48. $validator = validator::make(request()->all(), [
  49. 'email' => ['required', 'email'],
  50. 'password' => $passwdRules,
  51. ]);
  52. if ($validator->fails()) {
  53. return redirect()->back()
  54. ->withErrors($validator)
  55. ->withInput();
  56. }
  57. if ($this->checkDormantMember(request('email'))) {
  58. notify()->error('휴면상태로 전환된 계정입니다. 로그인을 하시면 휴면 상태를 해제하실 수 있습니다.', 'Error', 'bottomRight');
  59. return redirect()->back();
  60. }
  61. $response = $this->callApiService->callApi([
  62. 'url' => 'member-signup',
  63. 'data' => [
  64. 'Email' => request('email'),
  65. 'Password' => request('password'),
  66. 'SgroupCode' => request('sgroup_code'),
  67. 'MobileNo' => formatPhone(request('mobile_no')),
  68. 'FirstName' => request('first_name'),
  69. ]
  70. ]);
  71. if (isset($response['apiStatus'])) {
  72. notify()->error($response['body'], 'Error', 'bottomRight');
  73. return redirect()->back();
  74. }
  75. $this->mailTemplateService->send('msg.dabory.pro.ko_KR.email.auth.signup-confirm-1',
  76. [
  77. 'C11' => route('confirm', ['code' => $response['ActivateCode']])
  78. ],
  79. request('email'), sprintf('[%s] 회원가입을 확인해주세요.', config('app.name')));
  80. session()->forget('smsCert');
  81. // notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  82. return redirect()->route('member-go-email');
  83. }
  84. public function checkDormantMember($email)
  85. {
  86. $b64Email = base64_encode($email);
  87. $memberPage = $this->callApiService->callApi([
  88. 'url' => 'member-page',
  89. 'data' => [
  90. 'PageVars' => [
  91. 'Query' => "email = '$b64Email' and status = '5'",
  92. 'Limit' => 1, 'Offset' => 0
  93. ]
  94. ]
  95. ]);
  96. if ($this->callApiService->verifyApiError($memberPage)) {
  97. return false;
  98. }
  99. $member = $memberPage['Page'][0];
  100. if (isset($member) && $member['Status'] === '5') {
  101. return true;
  102. }
  103. return false;
  104. }
  105. public function activateCodeResend()
  106. {
  107. $response = $this->callApiService->callApi([
  108. 'url' => 'member-pick',
  109. 'data' => [
  110. 'Page' => [
  111. [ 'Email' => request('email') ]
  112. ]
  113. ]
  114. ]);
  115. if ($this->callApiService->verifyApiError($response)) {
  116. notify()->error('이메일 계정이 존재하지 않습니다', 'Error', 'bottomRight');
  117. return redirect()->back();
  118. }
  119. event(new UserCreated([
  120. 'email' => request('email'),
  121. 'activate_code' => $response['Page'][0]['ActivateCode']
  122. ]));
  123. // notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  124. return redirect()->route('member-go-email');
  125. }
  126. public function confirm()
  127. {
  128. $response = $this->callApiService->callApi([
  129. 'url' => 'member-activate',
  130. 'data' => [
  131. 'ActivateCode' => request('code'),
  132. ],
  133. ]);
  134. if (isset($response['apiStatus'])) {
  135. return redirect()->route('member-activate-failed');
  136. } else {
  137. return redirect()->route('member-verify-ok');
  138. }
  139. }
  140. }