private function updatePassword() { $this->load->file('application/modules/app/layout/layout_password_data.php'); $resAjax = new Response_Ajax(); $data = new Data_App_Layout_Password(TRUE); try { if (!$data->isValid()) { throw new Exception('Complete correctamente todos los campos'); } $id_user = Helper_App_Session::getUserId(); $oBus = Business_App_User::checkPassword($id_user, $data->password_current); if (!$oBus->isSuccess()) { throw new Exception($oBus->message()); } $data_isValid = $oBus->data(); $isValid = $data_isValid['isValid']; if (!$isValid) { throw new Exception('Contraseña incorrecta.'); } $oBus2 = Business_App_User::updatePassword($id_user, $data->password_new); if (!$oBus2->isSuccess()) { throw new Exception($oBus2->message()); } $data_changed = $oBus2->data(); $changed = $data_changed['changed']; if (!$changed) { throw new Exception("No fue posible cambiar la contraseña"); } $resAjax->isSuccess(TRUE); $resAjax->message("Contraseña cambiada con éxito."); } catch (Exception $ex) { $resAjax->isSuccess(FALSE); $resAjax->message($ex->getMessage()); $resAjax->form('change_password', $data->toArray()); } echo $resAjax->toJsonEncode(); }
private function changePassword() { $this->load->file('application/forms/app/login_change_password_form.php'); $resAjax = new Response_Ajax(); $oBus = new Response_Business(); $frmChangePassword = new Form_App_Login_Change_Password(TRUE); try { if (!$frmChangePassword->isValid()) { throw new Exception('Complete Correctamente los campo'); } $oBus = Business_App_Token::inactivarUserToken(Helper_Encrypt::decode($frmChangePassword->id_user), 'id_user'); if (!$oBus->isSuccess()) { throw new Exception($oBus->message()); } $oBus = Business_App_User::updatePassword(Helper_Encrypt::decode($frmChangePassword->id_user), $frmChangePassword->new_password); if (!$oBus->isSuccess()) { throw new Exception($oBus->message()); } $resAjax->isSuccess(TRUE); $resAjax->message($oBus->message()); } catch (Exception $ex) { $resAjax->isSuccess(FALSE); $resAjax->message($ex->getMessage()); $resAjax->form('changePassword', $frmChangePassword->toArray()); } echo $resAjax->toJsonEncode(); }
private function saveUser() { $this->load->file('application/modules/app/user_profile/form/user_form.php'); $resAjax = new Response_Ajax(); $frm_data = new Form_App_User(TRUE); try { if (!$this->permission->update) { throw new Exception('No tiene permisos para editar/actualizar'); } if (!$frm_data->isValid()) { throw new Exception('Debe ingresar la información en todos los campos'); } $oBus = Business_App_User::loadUser(Helper_App_Session::getUserId()); $data = $oBus->data(); $eUser = $data['eUser']; $oBus = Business_App_User::login($eUser->username, $frm_data->password_current); if (!$oBus->isSuccess()) { throw new Exception('Contraseña Incorrecta'); } $oBus = Business_App_User::updatePassword($eUser->id, $frm_data->password_new_repeat); $resAjax->isSuccess(TRUE); $resAjax->message('Contraseña Actualizada'); } catch (Exception $ex) { $resAjax->isSuccess(FALSE); $resAjax->message($ex->getMessage()); $resAjax->form('user', $frm_data->toArray()); } echo $resAjax->toJsonEncode(); }