|
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/Ps/ |
Upload File : |
<?php
namespace App\Controllers\Ps;
use \App\Controllers\Ps\PS_Controller;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class Changepassword 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' => 'Top Menu', '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';
if ($this->session->has('ps_au_id')) {
echo 'ok';
$userModel = new \App\Models\PsAdmUser();
$this->view_data['user'] = $userModel->find($this->session->get('ps_au_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\PsAdmUser();
$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\PsAdmUser();
$dataModel = array(
'password' => $dataUser::hash_password($this->request->getVar('repeat_new_password'))
);
$dataUser->update($this->view_data['user']->ps_au_id, $dataModel);
parent::setMessageAndLogout(false, true, $this->msgLib->scs_password_changed());
} 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('authdev');
}
$this->render->viewPasswordPage($this->content_views['table_view'], $this);
}
}