Please help from friends. I have a problem UPDATE PASSWORD MYTH AUTH can not be saved to the database, even though there is no error message at all. In the CONTROLLER I use PAGE DYNAMIC so here I can not display the controller as a whole.
in ROUTES:
$routes->get('/password','Home::profilPassword', ['filter' => 'role:Admin,User']);
In HOME CONTROLLER:
public function profilPassword(){
$q1=$this->pageBreadCrumb('profilpassword');
foreach($q1 as $key => $v1);
return $this->showProfil(strtoupper($v1['title']),ucwords($v1['description']),'profil/ubahpassword');
}
public function pageBreadCrumb($page){
return $this->db->table('breadcrumb')->where('page', $page)->get()->getResultArray();
}
public function showProfil(string $title, string $deskripsi, string $page){
$data = [
'title' =>
$title,'breadcrumb' => '<h4>'.$title.'</h4><p>'.$deskripsi.'</p>',
'page' => $page,
'kotalahir'=>$this->modelWilayah->namakota(),
];
return $this->_render('dynamic',$data);
}
in PAGE DYNAMIC
<!-- CODE HTML -->
<?=$page?> // Show FORM CHANGE PASSWORD
<! END CODE HTML –>
In VIEW:
<?= form_open_multipart('ubahpassword/'.user()->id)?>
<div class="form-group row">
<label for="passwordlama" class="col-sm-4 col-form-label"><?= lang('Auth.oldPassword') ?></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="passwordlama" id="passwordlama">
</div>
</div>
<div class="form-group row">
<label for="passwordbaru" class="col-sm-4 col-form-label"><?= lang('Auth.newPassword') ?></label>
<div class="col-sm-8">
<input type="password" class="form-control" name="passwordbaru" id="passwordbaru">
</div>
</div>
<div class="form-group row">
<label for="confirm_password" class="col-sm-4 col-form-label"><?=lang('Auth.newPasswordRepeat')?></label>
<div class="col-sm-8">
<input type="password" class="form-control" name="confirm_password" id="confirm_password">
</div>
</div>
<div class="form-group row justify-content-center">
<button type="submit" class="btn btn_1"><?=lang('Auth.update')?></button>
</div>
<?= form_close(); ?>
In FORM CONTROLLER:
namespace AppControllers;
use CodeIgniterController;
use (ALL) // everything related to myth/auth
class FormController extends Controller
{
public function ubah_password($id){
if ($this->request->getMethod() == 'POST') {
$rules=[
'passwordlama' => [
'label' => lang('Auth.oldPassword'),
'rules' => 'required|isCurrentPassword[passwordlama]',
],
'passwordbaru' => [
'label' => lang('Auth.newPassword'),
'rules' => 'required|strong_password|min_length[8]|max_length[12]', // As said before, it's only this part `strong_password`
],
'password_hash' => [
'label' => lang('Auth.newPasswordRepeat'),
'rules' => 'required|matches[passwordbaru]|min_length[8]|max_length[12]',
]
];
if(!$this->validate($rules)){
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}else{
//SAVE
$users = new UserModel();
$newPassword = $this->request->getVar('confirm_passwordh');
$this->entity->setPassword($newPassword);
$hash = $this->entity->password_hash;
if(!$users->update($id,['password_hash'=>$hash])){
return redirect()->back()->withInput()->with('error', $this->auth->error() ?? lang('Auth.invalidData'));
}else{
return redirect()->to('dashboard')->withInput()->with('message', lang('Auth.changePasswordSuccess'));
}
}
}
}
}
NB: There is no error message, all codes are fine, but during the UPDATE process the data cannot be saved in the DATABASE. Please help master. Thank you
There is no error message, all codes are fine, but during the UPDATE process the data cannot be saved in the DATABASE. Please help master. Thank you
Daarud Dhiyaafah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.