CompanySignupController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Themes\Pro\modunawa\app\Http\Controllers\Auth;
  3. use App\Helpers\File;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\CallApiService;
  6. use Illuminate\Support\Facades\Validator;
  7. use App\Events\UserCreated;
  8. class CompanySignupController extends Controller
  9. {
  10. private $callApiService;
  11. public function __construct(CallApiService $callApiService)
  12. {
  13. $this->callApiService = $callApiService;
  14. }
  15. public function index()
  16. {
  17. $passwdPolicy = setupPasswdPolicy('member');
  18. $smsCert = session('smsCert');
  19. if (empty($smsCert) || empty($smsCert['code'])) {
  20. notify()->error('잘못된 접근입니다', 'Error', 'bottomRight');
  21. return redirect()->route('member-signup-verify.index');
  22. }
  23. if ($smsCert['code'] !== 200) {
  24. notify()->error('인증실패', 'Error', 'bottomRight');
  25. return redirect()->route('member-signup-verify.index');
  26. }
  27. if (date('YmdHis') - $smsCert['date'] > 500) {
  28. session()->forget('smsCert');
  29. notify()->error('인증 시간이 만료되었습니다', 'Error', 'bottomRight');
  30. return redirect()->route('member-signup-verify.index');
  31. }
  32. return view('views.auth.member-company-signup', [
  33. 'policyDesc' => $passwdPolicy['PolicyDesc'],
  34. ]);
  35. }
  36. public function store()
  37. {
  38. $passwdPolicy = setupPasswdPolicy('member');
  39. if ($this->callApiService->verifyApiError($passwdPolicy)) {
  40. notify()->error($passwdPolicy['body'], 'Error', 'bottomRight');
  41. return redirect()->back();
  42. }
  43. $passwdRules = makePasswdRules($passwdPolicy);
  44. $validator = validator::make(request()->all(), [
  45. 'email' => ['required', 'email'],
  46. 'password' => $passwdRules,
  47. ]);
  48. if ($validator->fails()) {
  49. return redirect()->back()
  50. ->withErrors($validator)
  51. ->withInput();
  52. }
  53. if (request('van')) {
  54. $company_json = json_encode([
  55. 'Van' => request('van'),
  56. 'VanId' => request('van_id'),
  57. 'VanPw' => request('van_pw'),
  58. ]);
  59. }
  60. $response = $this->callApiService->callApi([
  61. 'url' => 'member-signup',
  62. 'data' => [
  63. 'Email' => request('email'),
  64. 'Password' => request('password'),
  65. 'MobileNo' => formatPhone(request('mobile_no')),
  66. 'FirstName' => request('first_name'),
  67. 'Sort' => '1',
  68. 'CompanyName' => request('company_name'),
  69. 'CompanyClass' => 'BB',
  70. 'TaxNo' => request('tax_no'),
  71. 'President' => request('president'),
  72. 'TelNo' => request('tel_no'),
  73. 'BizType' => request('biz_type'),
  74. 'DealItem' => request('deal_item'),
  75. 'ZipCode' => request('zip_code'),
  76. 'Addr1' => request('addr1'),
  77. 'Addr2' => request('addr2'),
  78. 'CertImg' => $this->uploadCertImage(),
  79. 'CompanyJson' => $company_json ?? ''
  80. ]
  81. ]);
  82. if ($this->callApiService->verifyApiError($response)) {
  83. notify()->error($response['body'], 'Error', 'bottomRight');
  84. return redirect()->back()->withInput();
  85. }
  86. // 가입확인 메일 보내는 이벤트
  87. event(new UserCreated([
  88. 'email' => request('email'),
  89. 'activate_code' => $response['ActivateCode']
  90. ]));
  91. session()->forget('smsCert');
  92. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  93. return redirect()->route('member-go-email');
  94. }
  95. public function uploadCertImage()
  96. {
  97. if (request()->hasFile('cert_img')) {
  98. return File::uploadImg(request()->file('cert_img'));
  99. }
  100. return null;
  101. }
  102. }