123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;
- use App\Http\Controllers\Controller;
- use App\Services\CallApiService;
- use App\Services\Msg\MailTemplateService;
- use Illuminate\Support\Facades\Validator;
- use App\Events\UserCreated;
- class SignupController extends Controller
- {
- private $callApiService;
- private $mailTemplateService;
- public function __construct(CallApiService $callApiService, MailTemplateService $mailTemplateService)
- {
- $this->callApiService = $callApiService;
- $this->mailTemplateService = $mailTemplateService;
- }
- public function index()
- {
- $passwdPolicy = setupPasswdPolicy('member');
- $smsCert = session('smsCert');
- // if (empty($smsCert) || empty($smsCert['code'])) {
- // notify()->error('잘못된 접근입니다', 'Error', 'bottomRight');
- // return redirect()->route('member-signup-verify.index');
- // }
- //
- // if ($smsCert['code'] !== 200) {
- // notify()->error('인증실패', 'Error', 'bottomRight');
- // return redirect()->route('member-signup-verify.index');
- // }
- //
- // if (date('YmdHis') - $smsCert['date'] > 500) {
- // session()->forget('smsCert');
- // notify()->error('인증 시간이 만료되었습니다', 'Error', 'bottomRight');
- // return redirect()->route('member-signup-verify.index');
- // }
- return view('views.auth.member-signup', [
- 'passwdPolicy' => $passwdPolicy,
- ]);
- }
- public function store()
- {
- $passwdPolicy = setupPasswdPolicy('member');
- if ($this->callApiService->verifyApiError($passwdPolicy)) {
- notify()->error($passwdPolicy['body'], 'Error', 'bottomRight');
- return redirect()->back();
- }
- $passwdRules = makePasswdRules($passwdPolicy);
- $validator = validator::make(request()->all(), [
- 'email' => ['required', 'email'],
- 'password' => $passwdRules,
- ]);
- if ($validator->fails()) {
- return redirect()->back()
- ->withErrors($validator)
- ->withInput();
- }
- if ($this->checkDormantMember(request('email'))) {
- notify()->error('휴면상태로 전환된 계정입니다. 로그인을 하시면 휴면 상태를 해제하실 수 있습니다.', 'Error', 'bottomRight');
- return redirect()->back();
- }
- $response = $this->callApiService->callApi([
- 'url' => 'member-signup',
- 'data' => [
- 'Email' => request('email'),
- 'Password' => request('password'),
- 'SgroupCode' => request('sgroup_code'),
- 'MobileNo' => formatPhone(request('mobile_no')),
- 'FirstName' => request('first_name'),
- ]
- ]);
- if (isset($response['apiStatus'])) {
- notify()->error($response['body'], 'Error', 'bottomRight');
- return redirect()->back();
- }
- $this->mailTemplateService->send('msg.dabory.pro.ko_KR.email.auth.signup-confirm-1',
- [
- 'C11' => route('confirm', ['code' => $response['ActivateCode']])
- ],
- request('email'), sprintf('[%s] 회원가입을 확인해주세요.', config('app.name')));
- session()->forget('smsCert');
- // notify()->success(_e('Action completed'), 'Success', 'bottomRight');
- return redirect()->route('member-go-email');
- }
- public function checkDormantMember($email)
- {
- $b64Email = base64_encode($email);
- $memberPage = $this->callApiService->callApi([
- 'url' => 'member-page',
- 'data' => [
- 'PageVars' => [
- 'Query' => "email = '$b64Email' and status = '5'",
- 'Limit' => 1, 'Offset' => 0
- ]
- ]
- ]);
- if ($this->callApiService->verifyApiError($memberPage)) {
- return false;
- }
- $member = $memberPage['Page'][0];
- if (isset($member) && $member['Status'] === '5') {
- return true;
- }
- return false;
- }
- public function activateCodeResend()
- {
- $response = $this->callApiService->callApi([
- 'url' => 'member-pick',
- 'data' => [
- 'Page' => [
- [ 'Email' => request('email') ]
- ]
- ]
- ]);
- if ($this->callApiService->verifyApiError($response)) {
- notify()->error('이메일 계정이 존재하지 않습니다', 'Error', 'bottomRight');
- return redirect()->back();
- }
- event(new UserCreated([
- 'email' => request('email'),
- 'activate_code' => $response['Page'][0]['ActivateCode']
- ]));
- // notify()->success(_e('Action completed'), 'Success', 'bottomRight');
- return redirect()->route('member-go-email');
- }
- public function confirm()
- {
- $response = $this->callApiService->callApi([
- 'url' => 'member-activate',
- 'data' => [
- 'ActivateCode' => request('code'),
- ],
- ]);
- if (isset($response['apiStatus'])) {
- return redirect()->route('member-activate-failed');
- } else {
- return redirect()->route('member-verify-ok');
- }
- }
- }
|