SignupController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use Illuminate\Support\Facades\Validator;
  6. use App\Events\UserCreated;
  7. class SignupController extends Controller
  8. {
  9. private $callApiService;
  10. public function __construct(CallApiService $callApiService)
  11. {
  12. $this->callApiService = $callApiService;
  13. }
  14. public function index()
  15. {
  16. $passwdPolicy = setupPasswdPolicy('users');
  17. $smsCert = session('smsCert');
  18. if (empty($smsCert) || empty($smsCert['code'])) {
  19. notify()->error('잘못된 접근입니다', 'Error', 'bottomRight');
  20. return redirect()->route('user-signup-verify.index');
  21. }
  22. if ($smsCert['code'] !== 200) {
  23. notify()->error('인증실패', 'Error', 'bottomRight');
  24. return redirect()->route('user-signup-verify.index');
  25. }
  26. if (date('YmdHis') - $smsCert['date'] > 500) {
  27. session()->forget('smsCert');
  28. notify()->error('인증 시간이 만료되었습니다', 'Error', 'bottomRight');
  29. return redirect()->route('user-signup-verify.index');
  30. }
  31. return view('auth.user-signup', [
  32. 'policyDesc' => $passwdPolicy['PolicyDesc'],
  33. ]);
  34. }
  35. public function store()
  36. {
  37. $passwdPolicy = setupPasswdPolicy('users');
  38. if ($this->callApiService->verifyApiError($passwdPolicy)) {
  39. notify()->error($passwdPolicy['body'], 'Error', 'bottomRight');
  40. return redirect()->back();
  41. }
  42. $passwdRules = makePasswdRules($passwdPolicy);
  43. $validator = validator::make(request()->all(), [
  44. 'email' => ['required', 'email'],
  45. 'password' => $passwdRules,
  46. ]);
  47. if ($validator->fails()) {
  48. return redirect()->back()
  49. ->withErrors($validator)
  50. ->withInput();
  51. }
  52. $response = $this->callApiService->callApi([
  53. 'url' => 'user-signup',
  54. 'data' => [
  55. 'Email' => request('email'),
  56. 'Password' => request('password'),
  57. 'SgroupCode' => request('sgroup_code'),
  58. 'MobileNo' => formatPhone(request('mobile_no')),
  59. ]
  60. ]);
  61. if (isset($response['apiStatus'])) {
  62. notify()->error($response['body'], 'Error', 'bottomRight');
  63. return redirect()->back();
  64. }
  65. // 가입확인 메일 보내는 이벤트
  66. event(new UserCreated([
  67. 'email' => request('email'),
  68. 'activate_code' => $response['ActivateCode'],
  69. 'route' => 'emails.auth.confirm',
  70. 'redirectUrl' => 'user-confirm'
  71. ]));
  72. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  73. return redirect()->route('user-go-email');
  74. }
  75. public function activateCodeResend()
  76. {
  77. $response = $this->callApiService->callApi([
  78. 'url' => 'user-pick',
  79. 'data' => [
  80. 'Page' => [
  81. [ 'Email' => request('email') ]
  82. ]
  83. ]
  84. ]);
  85. if ($this->callApiService->verifyApiError($response)) {
  86. notify()->error('이메일 계정이 존재하지 않습니다.', 'Error', 'bottomRight');
  87. return redirect()->back();
  88. }
  89. event(new UserCreated([
  90. 'email' => request('email'),
  91. 'activate_code' => $response['Page'][0]['ActivateCode']
  92. ]));
  93. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  94. return redirect()->route('user-go-email');
  95. }
  96. public function confirm()
  97. {
  98. $response = $this->callApiService->callApi([
  99. 'url' => 'user-activate',
  100. 'data' => [
  101. 'ActivateCode' => request('code'),
  102. ],
  103. ]);
  104. if (isset($response['apiStatus'])) {
  105. return redirect()->route('user-activate-failed');
  106. } else {
  107. return redirect()->route('user-verify-ok');
  108. }
  109. }
  110. }