|
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/www/simulasikite.mata-lashes.com/app/Controllers/Store/ |
Upload File : |
<?php
namespace App\Controllers\Store;
use \App\Controllers\Ps\PS_Controller;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class Storeubahpassword extends PS_Controller
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger); // TODO: Change the autogenerated stub
parent::setPageTitleBreadcrumb(false, 'Ubah Password', array('l1' => 'Store', 'l2' => 'Ubah Password'));
parent::setURLActionTable($this->class);
parent::setBaseContAndModel($this->class);
$this->content_views = array(
'table_view' => 'admin/pages/primary/password',
);
$this->validation_input = $this->validation->setRules([
"old_password" => ['label' => 'Password lama', 'rules' => 'required'],
"new_password" => ['label' => 'Password Baru', 'rules' => 'required|min_length[7]'],
"repeat_new_password" => ['label' => 'Input Ulang Password Baru', 'rules' => 'required|matches[new_password]'],
]);
}
public function index()
{
$this->view_data['button'] = 'Ubah Password';
$userall = new \App\Models\PsStoreUser();
$this->view_data['_userall'] = $userall->where('ps_sr_id!=', 1)->where('deleted_at', null)->findAll();
if ($this->session->has('ps_su_id')) {
$userModel = new \App\Models\PsStoreUser();
$this->view_data['user'] = $userModel->find($this->session->get('ps_su_id'));
if ($_POST) {
if (!$this->validation_input->withRequest($this->request)->run()) {
$this->view_data['error'] = true;
$this->view_data['message'] = 'Ada kesalahan dalam pengisian form!';
$this->view_data['error_list'] = $this->validation_input->getErrors();
} else {
$userModel = new \App\Models\PsStoreUser();
$user = $userModel->find($this->request->getVar('ps_su_id'));
$userModel = new \App\Models\PsStoreUser();
$result = $userModel::validate_password($user, $this->request->getVar('old_password'));
if ($result) {
if ($_POST['new_password'] != $_POST['old_password']) {
if ($this->request->getVar('repeat_new_password') == $this->request->getVar('new_password')) {
$dataUser = new \App\Models\PsStoreUser();
$dataModel = array(
'password' => $dataUser::hash_password($this->request->getVar('repeat_new_password'))
);
$dataUser->update($user->ps_su_id, $dataModel);
$dataUser2 = new \App\Models\PsStoreUser();
$dataUser2::logout($this);
parent::setMessageWithRedirect(false, true, $this->msgLib->scs_password_changed(), site_url('backoffice'));
} else {
parent::setMessage(true, false, $this->msgLib->err_password_not_match());
}
} else {
parent::setMessage(true, false, $this->msgLib->err_password_same());
}
} else {
parent::setMessage(true, false, $this->msgLib->err_password_wrong());
}
}
}
// if ($_POST) {
// if (!$this->validation_input->withRequest($this->request)->run()) {
// $this->view_data['error'] = true;
// $this->view_data['message'] = 'Ada kesalahan dalam pengisian form!';
// $this->view_data['error_list'] = $this->validation_input->getErrors();
// } else {
// $userModel = new \App\Models\PsStoreUser();
// $result = $userModel::validate_password($this->view_data['user'], $this->request->getVar('old_password'));
// if ($result) {
// if ($_POST['new_password'] != $_POST['old_password']) {
// if ($this->request->getVar('repeat_new_password') == $this->request->getVar('new_password')) {
// $dataUser = new \App\Models\PsStoreUser();
// $dataModel = array(
// 'password' => $dataUser::hash_password($this->request->getVar('repeat_new_password'))
// );
// $dataUser->update($this->view_data['user']->ps_su_id, $dataModel);
// $dataUser2 = new \App\Models\PsStoreUser();
// $dataUser2::logout($this);
// parent::setMessageWithRedirect(false, true, $this->msgLib->scs_password_changed(), site_url('authstore'));
// } else {
// parent::setMessage(true, false, $this->msgLib->err_password_not_match());
// }
// } else {
// parent::setMessage(true, false, $this->msgLib->err_password_same());
// }
// } else {
// parent::setMessage(true, false, $this->msgLib->err_password_wrong());
// }
// }
// }
} else {
return redirect()->route('authstore');
}
$this->render->viewPasswordPage($this->content_views['table_view'], $this);
}
}