Skip to content

Commit

Permalink
compatibility(MySQL) eliminate unbalanced transactions for strict sql…
Browse files Browse the repository at this point in the history
… and recreate user file on password change
  • Loading branch information
joebordes committed Oct 26, 2016
1 parent 1292764 commit e056079
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions modules/Users/Users.php
Expand Up @@ -412,19 +412,10 @@ function change_password($user_password, $new_password, $dieOnError = true) {
return false;
}

if (!is_admin($current_user)) {
$this->db->startTransaction();
if (!$this->verifyPassword($user_password)) {
$this->log->warn("Incorrect old password for $usr_name");
$this->error_string = $mod_strings['ERR_PASSWORD_INCORRECT_OLD'];
return false;
}
if ($this->db->hasFailedTransaction()) {
if ($dieOnError) {
die("error verifying old password[" . $this->db->database->ErrorNo() . "] " . $this->db->database->ErrorMsg());
}
return false;
}
if (!is_admin($current_user) and !$this->verifyPassword($user_password)) {
$this->log->warn("Incorrect old password for $usr_name");
$this->error_string = $mod_strings['ERR_PASSWORD_INCORRECT_OLD'];
return false;
}

//set new password
Expand All @@ -445,15 +436,10 @@ function change_password($user_password, $new_password, $dieOnError = true) {
$this->db->query("ALTER TABLE `vtiger_users` ADD `last_password_reset_date` date DEFAULT NULL");
}
$query = "UPDATE $this->table_name SET user_password=?, confirm_password=?, crypt_type=?, change_password=?, last_password_reset_date=now(), failed_login_attempts=0 where id=?";
$this->db->startTransaction();
$this->db->pquery($query, array($encrypted_new_password, $encrypted_new_password, $crypt_type, $change_password_next_login, $this->id));
if ($this->db->hasFailedTransaction()) {
if ($dieOnError) {
die("error setting new password: [" . $this->db->database->ErrorNo() . "] " . $this->db->database->ErrorMsg());
}
return false;
}
$this->createAccessKey();
require_once ('modules/Users/CreateUserPrivilegeFile.php');
createUserPrivilegesfile($this->id);
return true;
}

Expand Down Expand Up @@ -634,10 +620,10 @@ function saveentity($module, $fileid = '') {
}

function createAccessKey() {
global $adb, $log;
global $log;
$log->info("Entering Into function createAccessKey()");
$updateQuery = "update vtiger_users set accesskey=? where id=?";
$insertResult = $adb->pquery($updateQuery, array(vtws_generateRandomAccessKey(16), $this->id));
$insertResult = $this->db->pquery($updateQuery, array(vtws_generateRandomAccessKey(16), $this->id));
$log->info("Exiting function createAccessKey()");
}

Expand Down

0 comments on commit e056079

Please sign in to comment.