Skip to content

Commit

Permalink
reset brute force protection when user gets restored
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKay85 authored Dec 11, 2024
1 parent 7135f95 commit 4363f22
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions modules/Users/actions/SaveAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,29 @@ public function savePassword(Vtiger_Request $request) {
* @param Vtiger_Request Object
*/
public function restoreUser(Vtiger_Request $request) {
$moduleName = $request->getModule();
$record = $request->get('userid');

$recordModel = Users_Record_Model::getInstanceById($record, $moduleName);
$recordModel->set('status', 'Active');
$recordModel->set('id', $record);
$recordModel->set('mode', 'edit');
$recordModel->set('user_hash', $recordModel->getUserHash());
$recordModel->save();

$db = PearDatabase::getInstance();
$date_var = date('Y-m-d H:i:s');
$db->pquery("UPDATE vtiger_users SET deleted=?, date_modified=? WHERE id=?", array(0,$db->formatDate($date_var, true),$record));

$userModuleModel = Users_Module_Model::getInstance($moduleName);
$listViewUrl = $userModuleModel->getListViewUrl();

$response = new Vtiger_Response();
$response->setResult(array('message'=>vtranslate('LBL_USER_RESTORED_SUCCESSFULLY', $moduleName), 'listViewUrl' => $listViewUrl));
$response->emit();
$moduleName = $request->getModule();
$record = $request->get('userid');

$recordModel = Users_Record_Model::getInstanceById($record, $moduleName);
$recordModel->set('status', 'Active');
$recordModel->set('id', $record);
$recordModel->set('mode', 'edit');
$recordModel->set('user_hash', $recordModel->getUserHash());
$recordModel->save();

$db = PearDatabase::getInstance();
$date_var = date('Y-m-d H:i:s');
$db->pquery("UPDATE vtiger_users SET deleted=?, date_modified=? WHERE id=?", array(0,$db->formatDate($date_var, true),$record));
// reset brute force protection
$query = "DELETE FROM berli_failed_logins WHERE user_name = ?;";
$db->pquery($query, array($recordModel->get('user_name')));

$userModuleModel = Users_Module_Model::getInstance($moduleName);
$listViewUrl = $userModuleModel->getListViewUrl();

$response = new Vtiger_Response();
$response->setResult(array('message'=>vtranslate('LBL_USER_RESTORED_SUCCESSFULLY', $moduleName), 'listViewUrl' => $listViewUrl));
$response->emit();
}

public function changeAccessKey(Vtiger_Request $request) {
Expand Down

0 comments on commit 4363f22

Please sign in to comment.