| 
				Server : Apache System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : matalashes ( 1004) PHP Version : 8.1.29 Disable Function : NONE Directory : /home/matalashes/.trash/app.bak.3/Controllers/Store/  | 
Upload File :  | 
<?php
namespace App\Controllers\Store;
use App\Controllers\Ps\PS_Controller;
use App\Models\PsAdmNewPasswordVerification;
use App\Models\PsAdmUser;
use App\Models\PsStoreNewPasswordVerification;
use App\Models\PsStoreUser;
use App\Models\PsStoreAccount;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use Config\Services;
class Authstore extends PS_Controller
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger); // TODO: Change the autogenerated stub
    }
    public function dashboard()
    {
        $this->view_data['base_controller'] = site_url('dashboardstore');
        $this->view_data['page_title'] = "Dashboard";
        $this->view_data['breadcrumb'] = array('l1' => 'Dashboard', 'link2' => '');
        $this->render->viewAdmin('admin/pages/primary/store/dashboard', $this);
    }
    public function login()
    {
        if ($this->session->has('ps_su_id')) {
            return redirect()->route('dashboardstore');
        } else {
            if ($_POST) {
                // $reCaptcha = $this->myLib->verify_reCaptchaV2($this->request->getVar('g-recaptcha-response'));
                // if ($reCaptcha['success']) {
                    $dataUser = new PsStoreUser();
                    $user = $dataUser::check_login($this->request->getVar('user_name_admin'), $this->request->getVar('password'));
                    if ($user == 'false') {
                        session()->setFlashdata('error', $this->msgLib->err_login());
                        return redirect()->back()->withInput();
                    } else if($user == 'expired'){
                        session()->setFlashdata('error', 'Masa Aktif akun Anda habis, silahkan menghubungi tim Qooick untuk memperbarui masa aktif akun Anda');
                        return redirect()->back()->withInput();
                    } else {
                        return redirect()->route('dashboardstore');
                    }
                // } else {
                //     session()->setFlashdata('error', $this->msgLib->err_captcha());
                //     return redirect()->back()->withInput();
                // }
            }
        }
        $this->render->viewLogin('admin/pages/primary/store/login', $this);
    }
    public function forgot()
    {
        if ($this->session->has('ps_su_id')) {
            return redirect()->route('dashboardstore');
        } else {
            if ($_POST) {
                // $reCaptcha = $this->myLib->verify_reCaptchaV2($this->request->getVar('g-recaptcha-response'));
                // if ($reCaptcha['success']) {
                    $dataUser = new PsStoreUser();
                    $user = $dataUser::check_email($this->request->getVar('user_email'));
                    if (!$user) {
                        parent::setMessage(true, false, $this->msgLib->err_forgotpassword());
                    } else {
                        $model = new PsStoreNewPasswordVerification();
                        $data = [
                            'ps_su_id' => $user->ps_su_id,
                            'snpv_link' => $model->getVerificationLink($this->request->getVar('user_email')),
                            'snpv_status' => 0,
                        ];
                        $model->save($data);
                        parent::setMessageWithRedirect(false, true, $this->msgLib->scs_forgotpassword(), site_url('backoffice'));
                    }
                // } else {
                //     parent::setMessage(true, false, $this->msgLib->err_captcha());
                // }
            }
        }
        $this->render->viewLogin('admin/pages/primary/store/forgotpassword', $this);
    }
    public function reset($link = '')
    {
        if ($link != '') {
            $model = new PsStoreNewPasswordVerification();
            $data = $model->getByLink($link);
            if ($data) {
                $d1 = new \DateTime(date('Y-m-d H:i:s'));
                $d2 = new \DateTime($data->created_at);
                $interval = $d1->diff($d2);
                if ($data->snpv_status == 0 && $interval->h < 24) {
                    if ($_POST) {
                        $reCaptcha = $this->myLib->verify_reCaptchaV2($this->request->getVar('g-recaptcha-response'));
                        if ($reCaptcha['success']) {
                            if ($this->request->getVar('user_password_confirm') == $this->request->getVar('user_password')) {
                                $_data = [
                                    'snpv_status' => 1,
                                    'deleted_at' => date('Y-m-d H:i:s'),
                                ];
                                $model->update($data->ps_snpv_id, $_data);
                                $user = new PsStoreUser();
                                $password = $user::hash_password($this->request->getVar('user_password_confirm'));
                                $user->update($data->ps_su_id, ['password' => $password]);
                                parent::setMessageWithRedirect(false, true, $this->msgLib->scs_newpassword(), site_url('backoffice'));
                            } else {
                                parent::setMessage(true, false, $this->msgLib->err_newpassword());
                            }
                        } else {
                            parent::setMessage(true, false, $this->msgLib->err_captcha());
                        }
                    }
                    $this->view_data['link'] = $link;
                    $this->render->viewLogin('admin/pages/primary/store/newpassword', $this);
                } else {
                    //link expired
                    return redirect()->route('expired');
                }
            } else {
                return redirect()->route('override404');
            }
        } else {
            return redirect()->route('backoffice');
        }
    }
    public function expired()
    {
        parent::setMessageWithRedirect(true, false, $this->msgLib->err_verificationlink(), site_url('backoffice'));
        $this->render->viewLogin('admin/pages/primary/store/login', $this);
    }
    public function logout()
    {
        $dataUser = new PsStoreUser();
        $dataUser::logout($this);
        return redirect()->route('backoffice');
    }
}