MemberUnlockController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;
  3. use App\Http\Traits\FetchesData\BasicTrait;
  4. use App\Services\CallApiService;
  5. use App\Services\Msg\MailTemplateService;
  6. use App\ThirdPartyApi\Interfaces\SmsInterface;
  7. class MemberUnlockController
  8. {
  9. private $callApiService;
  10. private $smsService;
  11. private $mailTemplateService;
  12. use BasicTrait;
  13. public function __construct(
  14. CallApiService $callApiService,
  15. SmsInterface $smsService,
  16. MailTemplateService $mailTemplateService)
  17. {
  18. $this->callApiService = $callApiService;
  19. $this->smsService = $smsService;
  20. $this->mailTemplateService = $mailTemplateService;
  21. }
  22. public function index()
  23. {
  24. $email = session('email', '');
  25. // $email = session('email');
  26. // if (empty($email)) {
  27. // notify()->error('잘 못 된 접근 입니다', 'Error', 'bottomRight');
  28. // return redirect()->back();
  29. // }
  30. return view('views.auth.member-unlock', compact('email'));
  31. }
  32. public function store()
  33. {
  34. if (request('cert_number') != session('smsCert.number')) {
  35. notify()->error(_e('Action failed'), 'Error', 'bottomRight');
  36. return redirect()->back()->withInput();
  37. }
  38. $response = $this->callApiService->callApi([
  39. 'url' => 'member-mobile-auth-passed',
  40. 'data' => [
  41. 'Email' => request('email'),
  42. 'SingleUse' => request('single_use') === '1'
  43. ],
  44. ]);
  45. if ($this->callApiService->verifyApiError($response)) {
  46. notify()->error($response['body'], 'Error', 'bottomRight');
  47. return redirect()->back();
  48. }
  49. $this->mailTemplateService->send('msg.dabory.pro.ko_KR.email.auth.new-device-login-1',
  50. [
  51. 'C11' => $response['DeviceDesc'],
  52. 'C12' => $response['DeviceIp'],
  53. 'C13' => route('member-device-block.store', ['code' => $response['ResetCode'], 'device_id' => $response['DeviceId']])
  54. ],
  55. request('email'), sprintf('[%s] 새로운 기기/장소에서 로그인(인증) 시도됨.', config('app.name')));
  56. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  57. return redirect()->route('member-login');
  58. }
  59. public function sendCert()
  60. {
  61. $member = $this->pick('member', [ 'Email' => request('email') ])['Data'];
  62. $memberExt = $this->pick('member-ext', [ 'Id' => $member['Id'] ])['Data'];
  63. $mobileNo = $memberExt['MobileNo'];
  64. $smsCert = rand(100000, 999999);
  65. $reqInfo = [
  66. 'number' => $smsCert,
  67. 'date' => date('YmdHis'),
  68. 'mobile_no' => $mobileNo
  69. ];
  70. $title ='본인확인';
  71. $msg ="[Dabory] 본인확인 인증번호는 [{$smsCert}]입니다. 정확히 입력해주세요.";
  72. $receiver = $mobileNo;
  73. session()->put('smsCert', $reqInfo);
  74. $response = $this->smsService->sendMessage($title, $msg, $receiver);
  75. return response()->json($response);
  76. }
  77. }