From 1867f0b93e4bc040f22bcba4cdb734455fd24dc6 Mon Sep 17 00:00:00 2001
From: AntonLV
Date: Wed, 11 Sep 2024 10:59:31 +0300
Subject: [PATCH] Ticket #4797 - Need Change Password feature always asks to
change password.
---
inc/classes/BxDolAccount.php | 101 +++++++---------
inc/classes/BxDolAccountQuery.php | 50 ++++----
inc/classes/BxDolAclQuery.php | 27 ++++-
inc/classes/BxDolCronAccount.php | 40 +++---
install/sql/system.sql | 2 +-
.../boonex/english/data/langs/system/en.xml | 6 +-
.../boonex/russian/data/langs/system/ru.xml | 6 +
template/scripts/BxBaseFormAccount.php | 114 ++++++++++--------
template/scripts/BxBaseServiceAccount.php | 18 +--
9 files changed, 189 insertions(+), 175 deletions(-)
diff --git a/inc/classes/BxDolAccount.php b/inc/classes/BxDolAccount.php
index 8c5c6b1fa4..bbeaea0d80 100644
--- a/inc/classes/BxDolAccount.php
+++ b/inc/classes/BxDolAccount.php
@@ -291,15 +291,14 @@ public function updatePhoneConfirmed($isConfirmed, $iAccountId = false)
*/
public function updatePassword($sPassword, $iAccountId = false)
{
+ $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
+
$sSalt = genRndSalt();
$sPasswordHash = encryptUserPwd($sPassword, $sSalt);
- $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
- $oAccountSender = BxDolAccount::getInstance();
$this->_oQuery->logPassword($iId);
- $iPasswordExpired = $this->getPasswordExpiredDateByAccount($iAccountId);
- if((int)$this->_oQuery->updatePassword($sPasswordHash, $sSalt, $iId, $iPasswordExpired) > 0) {
+ if((int)$this->_oQuery->updatePassword($sPasswordHash, $sSalt, $iId) > 0) {
/**
* @hooks
* @hookdef hook-account-edited 'account', 'edited' - hook on account edited $oAccount->updatePassword
@@ -311,10 +310,14 @@ public function updatePassword($sPassword, $iAccountId = false)
* - `action` - [string] action's name, can be reset_password
* @hook @ref hook-account-edited
*/
- bx_alert('account', 'edited', $iId, $oAccountSender ? $oAccountSender->id() : $iId, array('action' => 'reset_password'));
+ bx_alert('account', 'edited', $iId, ($iSenderId = getLoggedId()) != 0 ? $iSenderId : $iId, [
+ 'action' => 'reset_password'
+ ]);
+
$this->doAudit($iId, '_sys_audit_action_account_reset_password');
return true;
}
+
return false;
}
/**
@@ -847,54 +850,32 @@ public function getEmailHash($iAccountId = false)
return md5($a['email'] . $a['salt'] . BX_DOL_SECRET);
}
- public function getPasswordExpiredDate($iPasswordExpiredForMembership, $iAccountId = false)
+ public function getPasswordChangedDate($mixedAccount = false)
{
- if ($iPasswordExpiredForMembership == 0)
- return 0;
-
- $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
-
- $aAccountInfo = $this->_oQuery->getInfoById($iAccountId);
-
- $iLastPassChanged = $this->_oQuery->getLastPasswordChanged($iAccountId);
- if ($iLastPassChanged == 0)
- $iLastPassChanged = $aAccountInfo['added'];
+ if(($bEmpty = empty($mixedAccount)) || !is_array($mixedAccount))
+ $mixedAccount = $this->_oQuery->getInfoById(!$bEmpty ? (int)$mixedAccount : $this->_iAccountID);
- return $iPasswordExpiredForMembership * 86400 + $iLastPassChanged;
+ $iLastChanged = (int)$mixedAccount['password_changed'];
+ return $iLastChanged ? $iLastChanged : (int)$mixedAccount['added'];
}
-
- public function getPasswordExpiredDateByAccount($iAccountId = false)
+
+ public function getPasswordExpiredDate($iPasswordExpiredForMembership, $mixedAccount = false)
{
- $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
-
- $oACL = BxDolAcl::getInstance();
-
- $aProfiles = BxDolAccount::getInstance($iAccountId)->getProfiles();
- $iPasswordExpiredForMembership = 0;
- foreach ($aProfiles as $aProfile) {
- $aMembersipInfo = $oACL->getMemberMembershipInfo($aProfile['id']);
- $Memberships = [];
- BxDolAclQuery::getInstance()->getLevels(['type' => 'by_id', 'value' => $aMembersipInfo['id']], $aMembership);
- if($aMembership['password_expired'] > 0){
- if ($iPasswordExpiredForMembership > 0 && $aMembership['password_expired'] < $iExpired)
- $iPasswordExpiredForMembership = $aMembership['password_expired'];
- if ($iPasswordExpiredForMembership == 0 )
- $iPasswordExpiredForMembership = $aMembership['password_expired'];
- }
- }
+ if($iPasswordExpiredForMembership == 0)
+ return 0;
- return $this->getPasswordExpiredDate($iPasswordExpiredForMembership, $iAccountId);
+ return $iPasswordExpiredForMembership * 86400 + $this->getPasswordChangedDate($mixedAccount);
}
-
+
public function isNeedChangePassword($iAccountId = false, $oInformer = false)
{
$iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
-
- $aAccountInfo = $this->getInfo();
+
list($sPageLink, $aPageParams) = bx_get_base_url_inline();
- $bNeedRedirectToChangePassword = true;
- if (isset($aPageParams['i']) && $aPageParams['i'] == 'account-settings-password')
+ $sChangePasswordUri = 'account-settings-password';
+ $bNeedRedirectToChangePassword = true;
+ if(isset($aPageParams['i']) && $aPageParams['i'] == $sChangePasswordUri)
$bNeedRedirectToChangePassword = false;
/**
@@ -908,31 +889,39 @@ public function isNeedChangePassword($iAccountId = false, $oInformer = false)
* - `override_result` - [bool] by ref, if Need Redirect To Change Password = true, otherwise = false, can be overridden in hook processing
* @hook @ref hook-account-is_need_to_change_password
*/
- bx_alert('account', 'is_need_to_change_password', $iAccountId, false, ['override_result' => &$bNeedRedirectToChangePassword]);
-
- if ($aAccountInfo['password_expired'] > 0 && $aAccountInfo['password_expired'] < time() && $bNeedRedirectToChangePassword) {
- if (getParam('sys_account_accounts_force_password_change_after_expiration') == 'on'){
- header('Location: ' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-password'));
+ bx_alert('account', 'is_need_to_change_password', $iAccountId, false, [
+ 'override_result' => &$bNeedRedirectToChangePassword
+ ]);
+
+ if(!$bNeedRedirectToChangePassword)
+ return;
+
+ $aAccountInfo = $this->getInfo();
+ $aMembershipInfo = BxDolAcl::getInstance()->getMemberMembershipInfo($aAccountInfo['profile_id']);
+ $sChangePasswordUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sChangePasswordUri);
+
+ if(($iPasswordExpiredDate = $this->getPasswordExpiredDate($aMembershipInfo['password_expired'], $aAccountInfo)) && $iPasswordExpiredDate < time()) {
+ if(getParam('sys_account_accounts_force_password_change_after_expiration') == 'on') {
+ header('Location: ' . $sChangePasswordUrl);
exit;
}
else {
if(!$oInformer)
$oInformer = BxDolInformer::getInstance();
- $oInformer->add('sys-account-need-to-change-password', _t('_sys_txt_account_need_to_change_password', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-password')), BX_INFORMER_ALERT);
+ $oInformer->add('sys-account-need-to-change-password', _t('_sys_txt_account_need_to_change_password', $sChangePasswordUrl), BX_INFORMER_ALERT);
}
}
}
-
- public function doAudit($iAccountId, $sAction, $aData = array())
+
+ public function doAudit($iAccountId, $sAction, $aData = [])
{
$iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
- bx_audit(
- $iAccountId,
- 'bx_accounts',
- $sAction,
- array('content_title' => $this->getEmail(), 'data' => $aData)
- );
+
+ bx_audit($iAccountId, 'bx_accounts', $sAction, [
+ 'content_title' => $this->getEmail(),
+ 'data' => $aData
+ ]);
}
/**
diff --git a/inc/classes/BxDolAccountQuery.php b/inc/classes/BxDolAccountQuery.php
index cfbeb5d122..493c1441ea 100644
--- a/inc/classes/BxDolAccountQuery.php
+++ b/inc/classes/BxDolAccountQuery.php
@@ -158,10 +158,13 @@ public function isOnline($iId)
* @param $iAccountId - account id to update password for
* @return number of affected rows
*/
- public function updatePassword($sPasswordHash, $sSalt, $iAccountId, $iPasswordExpired)
+ public function updatePassword($sPasswordHash, $sSalt, $iAccountId)
{
- $sQuery = $this->prepare("UPDATE `sys_accounts` SET `password` = ?, `salt` = ?, `password_expired` = ? WHERE `id`= ?", $sPasswordHash, $sSalt, $iPasswordExpired, $iAccountId);
- return $this->query($sQuery);
+ return $this->query("UPDATE `sys_accounts` SET `password` = :password, `salt` = :salt, `password_changed` = UNIX_TIMESTAMP() WHERE `id` = :id", [
+ 'id' => $iAccountId,
+ 'password' => $sPasswordHash,
+ 'salt' => $sSalt
+ ]);
}
/**
@@ -173,23 +176,24 @@ public function updatePassword($sPasswordHash, $sSalt, $iAccountId, $iPasswordEx
*/
public function logPassword($iAccountId)
{
- $iCountPassword = (int)getParam('sys_account_accounts_password_log_count');
-
- if ($iCountPassword > 0){
- $sSql = $this->prepare("SELECT `password`, `salt` FROM `sys_accounts` WHERE `id` = ?", $iAccountId);
- $aAccount = $this->getRow($sSql);
-
- $sQuery = "INSERT INTO `sys_accounts_password` (`password`, `password_changed`, `salt`, `account_id`) VALUES(:password, :password_changed, :salt, :account_id)";
- $aBindings = array(
- 'password' => $aAccount['password'],
- 'password_changed' => time(),
- 'salt' => $aAccount['salt'],
- 'account_id' => $iAccountId,
- );
- $this->query($sQuery, $aBindings);
-
- $this->query($this->prepare("DELETE FROM `sys_accounts_password` WHERE `id` NOT IN (SELECT `id` FROM (SELECT `id` FROM `sys_accounts_password` WHERE `account_id` = ? ORDER BY `password_changed` DESC LIMIT 0, " . getParam('sys_account_accounts_password_log_count') . ") a)", $iAccountId));
- }
+ $iCount = (int)getParam('sys_account_accounts_password_log_count');
+ if($iCount <= 0)
+ return;
+
+ $aAccount = $this->getRow("SELECT `password`, `password_changed`, `salt` FROM `sys_accounts` WHERE `id` = :id", [
+ 'id' => $iAccountId
+ ]);
+
+ $this->query("INSERT INTO `sys_accounts_password` SET " . $this->arrayToSQL([
+ 'account_id' => $iAccountId,
+ 'password' => $aAccount['password'],
+ 'password_changed' => $aAccount['password_changed'],
+ 'salt' => $aAccount['salt'],
+ ]));
+
+ $this->query("DELETE FROM `sys_accounts_password` WHERE `id` NOT IN (SELECT `id` FROM (SELECT `id` FROM `sys_accounts_password` WHERE `account_id` = :account_id ORDER BY `password_changed` DESC LIMIT 0, " . $iCount . ") AS `tap`)", [
+ 'account_id' => $iAccountId
+ ]);
}
public function getLastPasswordChanged($iAccountId)
@@ -204,12 +208,6 @@ public function getLastPasswordLog($iAccountId)
return $this->getAll($sSql);
}
- public function updatePasswordExpired($iAccountId, $iPasswordExpired)
- {
- $sQuery = $this->prepare("UPDATE `sys_accounts` SET `password_expired` = ? WHERE `id`= ?", $iPasswordExpired, $iAccountId);
- return $this->query($sQuery);
- }
-
/**
* Update last logged in time
* @param int $iID account id
diff --git a/inc/classes/BxDolAclQuery.php b/inc/classes/BxDolAclQuery.php
index f96ae7b93d..c72979b407 100644
--- a/inc/classes/BxDolAclQuery.php
+++ b/inc/classes/BxDolAclQuery.php
@@ -105,6 +105,10 @@ function getLevels($aParams, &$aItems, $bReturnCount = true)
case 'password_can_expired':
$sWhereClause .= "AND `tal`.`PasswordExpired` <> 0";
break;
+
+ case 'password_expired_notify':
+ $sWhereClause .= "AND `tal`.`PasswordExpired` <> 0 AND tal`.`PasswordExpiredNotify` <> 0";
+ break;
case 'all':
break;
@@ -239,6 +243,7 @@ function getLevelCurrent($iProfileId, $iTime = 0)
`sys_acl_levels`.`QuotaSize` AS `quota_size`,
`sys_acl_levels`.`QuotaNumber` AS `quota_number`,
`sys_acl_levels`.`QuotaMaxFileSize` AS `quota_max_file_size`,
+ `sys_acl_levels`.`PasswordExpired` AS `password_expired`,
UNIX_TIMESTAMP(`sys_acl_levels_members`.`DateStarts`) as `date_starts`,
UNIX_TIMESTAMP(`sys_acl_levels_members`.`DateExpires`) as `date_expires`,
`sys_acl_levels_members`.`State` AS `state`,
@@ -263,7 +268,8 @@ function getLevelByIdCached($iLevel)
`tal`.`Name` AS `name`,
`tal`.`QuotaSize` AS `quota_size`,
`tal`.`QuotaNumber` AS `quota_number`,
- `tal`.`QuotaMaxFileSize` AS `quota_max_file_size`
+ `tal`.`QuotaMaxFileSize` AS `quota_max_file_size`,
+ `tal`.`PasswordExpired` AS `password_expired`
FROM `sys_acl_levels` AS `tal`
WHERE `tal`.`ID`=?
LIMIT 1", $iLevel);
@@ -470,11 +476,26 @@ function getContentByActionAsSQLPart($sContentTable, $sContentField, $mixedActio
);
}
- function getProfilesByMembership($mixedLevelId)
+ function getProfilesByMembership($mixedLevelId, $aParams = [])
{
+ $sSelectClause = $sJoinClause = $sWhereClause = '';
+
$aSqlParts = $this->getContentByLevelAsSQLPart('sys_profiles', 'id', $mixedLevelId);
+ if(isset($aSqlParts['join'], $aSqlParts['where'])) {
+ $sJoinClause = $aSqlParts['join'];
+ $sWhereClause = $aSqlParts['where'];
+ }
+
+ if(isset($aParams['password_expired'], $aParams['password_expired_notify'])) {
+ $iExpire = (int)$aParams['password_expired'] * 86400;
+ $iNotify = ($iExpire - (int)$aParams['password_expired_notify']) * 86400;
+
+ $sSelectClause .= ", `ta`.`email` AS `email`, IF(`ta`.`password_changed` <> 0, `ta`.`password_changed`, `ta`.`added`) + " . $iExpire . " AS `password_expired`";
+ $sJoinClause .= " LEFT JOIN `sys_accounts` AS `ta` ON `sys_profiles`.`account_id`=`ta`.`id`";
+ $sWhereClause .= " AND IF(`ta`.`password_changed` <> 0, `ta`.`password_changed`, `ta`.`added`) + " . $iNotify . " < UNIX_TIMESTAMP() AND IF(`ta`.`password_changed` <> 0, `ta`.`password_changed`, `ta`.`added`) + " . $iExpire . " >= UNIX_TIMESTAMP()";
+ }
- return $this->getAll("SELECT `sys_profiles`.* FROM `sys_profiles`" . $aSqlParts['join'] . " WHERE 1" . $aSqlParts['where']);
+ return $this->getAll("SELECT `sys_profiles`.*" . $sSelectClause . " FROM `sys_profiles`" . $sJoinClause . " WHERE 1" . $sWhereClause);
}
function getProfilesByAction($mixedActionName, $aParams = [])
diff --git a/inc/classes/BxDolCronAccount.php b/inc/classes/BxDolCronAccount.php
index be651a20ff..e847d71e11 100644
--- a/inc/classes/BxDolCronAccount.php
+++ b/inc/classes/BxDolCronAccount.php
@@ -24,42 +24,32 @@ public function processing()
{
set_time_limit(0);
ignore_user_abort();
-
- $aEmails = [];
-
+
/* password expired soon email */
bx_import('BxTemplAcl');
$oAclDb = BxDolAclQuery::getInstance();
- $oAccountDb = BxDolAccountQuery::getInstance();
+ $aEmails = [];
$aMemberships = [];
- $oAclDb->getLevels(['type' => 'password_can_expired'], $aMemberships, false);
+ $oAclDb->getLevels(['type' => 'password_expired_notify'], $aMemberships, false);
foreach($aMemberships as $aMembership) {
- $aProfiles = $oAclDb->getProfilesByMembership([$aMembership['id']]);
+ $aProfiles = $oAclDb->getProfilesByMembership([$aMembership['id']], [
+ 'password_expired' => $aMembership['password_expired'],
+ 'password_expired_notify' => $aMembership['password_expired_notify']
+ ]);
+
foreach($aProfiles as $aProfile) {
- $oAccount = BxDolAccount::getInstance($aProfile['account_id']);
- if(!$oAccount)
+ if(in_array($aProfile['email'], $aEmails))
continue;
- $iPasswordExpired = $oAccount->getPasswordExpiredDate($aMembership['password_expired']);
- $aAccountInfo = $oAccountDb->getInfoById($aProfile['account_id']);
- $iLastPassChanged = $oAccountDb->getLastPasswordChanged($aProfile['account_id']);
- if (
- !in_array($aAccountInfo['email'], $aEmails)
- && ($aMembership['password_expired'] - $aMembership['password_expired_notify']) * 86400 + $iLastPassChanged < time()
- && $iPasswordExpired >= time()
- ){
- $aPlus = array();
- $aPlus['expired_date'] = date('d.m.Y', $iPasswordExpired);
- $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_AccountPasswordExpired', $aPlus);
-
- sendMail($aAccountInfo['email'], $aTemplate['Subject'], $aTemplate['Body'], $aProfile['id']);
- $aEmails[] = $aAccountInfo['email'];
- }
-
- $oAccountDb->updatePasswordExpired($aProfile['account_id'], $iPasswordExpired);
+ $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_AccountPasswordExpired', [
+ 'expired_date' => date('d.m.Y', $aProfile['password_expired'])
+ ]);
+
+ sendMail($aProfile['email'], $aTemplate['Subject'], $aTemplate['Body'], $aProfile['id']);
+ $aEmails[] = $aProfile['email'];
}
}
diff --git a/install/sql/system.sql b/install/sql/system.sql
index 1229d705c6..4d15340131 100644
--- a/install/sql/system.sql
+++ b/install/sql/system.sql
@@ -1378,7 +1378,7 @@ CREATE TABLE `sys_accounts` (
`referred` varchar(255) NOT NULL DEFAULT '',
`login_attempts` tinyint(4) NOT NULL DEFAULT '0',
`locked` tinyint(4) NOT NULL DEFAULT '0',
- `password_expired` int(11) NOT NULL DEFAULT '0',
+ `password_changed` int(11) NOT NULL DEFAULT '0',
`active` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`(191)),
diff --git a/modules/boonex/english/data/langs/system/en.xml b/modules/boonex/english/data/langs/system/en.xml
index 436fbfac61..42b3c352e5 100644
--- a/modules/boonex/english/data/langs/system/en.xml
+++ b/modules/boonex/english/data/langs/system/en.xml
@@ -2569,7 +2569,7 @@ If it is not enabled then please consider implement this optimization, since it
{account_output}
{email_footer}]]>
Your password will expired in {expired_date}
+Your password will expire {expired_date}
Please, sign-in and change password
{email_footer}]]>
-
+
@@ -2653,7 +2653,7 @@ If it is not enabled then please consider implement this optimization, since it
-
+
diff --git a/modules/boonex/russian/data/langs/system/ru.xml b/modules/boonex/russian/data/langs/system/ru.xml
index 54bf991df2..f9783efe1a 100644
--- a/modules/boonex/russian/data/langs/system/ru.xml
+++ b/modules/boonex/russian/data/langs/system/ru.xml
@@ -2544,6 +2544,10 @@
{email_footer}]]>
{account_output}
+{email_footer}]]>
+ Срок действия вашего пароля истекает {expired_date}
+Пожалуйста, войдите в систему и измените пароль.
{email_footer}]]>
{pruning_output}
@@ -2603,6 +2607,7 @@
+
@@ -2626,6 +2631,7 @@
+
diff --git a/template/scripts/BxBaseFormAccount.php b/template/scripts/BxBaseFormAccount.php
index 56f25e5fbf..83248a3e29 100644
--- a/template/scripts/BxBaseFormAccount.php
+++ b/template/scripts/BxBaseFormAccount.php
@@ -114,14 +114,15 @@ function checkEmailUniq ($s)
*/
class BxBaseFormAccount extends BxTemplFormView
{
- static $FIELD_EMAIL = 'email';
+ static $FIELD_EMAIL = 'email';
static $FIELD_PASSWORD = 'password';
+ static $FIELD_PASSWORD_CHANGED = 'password_changed';
static $FIELD_SALT = 'salt';
static $FIELD_ADDED = 'added';
static $FIELD_CHANGED = 'changed';
static $FIELD_IP = 'ip';
static $FIELD_REFERRED = 'referred';
- static $FIELD_PHONE = 'phone';
+ static $FIELD_PHONE = 'phone';
protected $_bSetPendingApproval = false;
@@ -176,81 +177,90 @@ public function setPendingApproval($b)
public function insert ($aValsToAdd = array(), $isIgnore = false)
{
+ $iNow = time();
+
$sEmail = isset($aValsToAdd[self::$FIELD_EMAIL]) ? $aValsToAdd[self::$FIELD_EMAIL] : $this->getCleanValue(self::$FIELD_EMAIL);
$sEmail = trim(strtolower($sEmail));
-
- $sPhone = isset($aValsToAdd[self::$FIELD_PHONE]) ? $aValsToAdd[self::$FIELD_PHONE] : $this->getCleanValue(self::$FIELD_PHONE);
+
+ $sPhone = isset($aValsToAdd[self::$FIELD_PHONE]) ? $aValsToAdd[self::$FIELD_PHONE] : $this->getCleanValue(self::$FIELD_PHONE);
$sPhone = trim(strtolower($sPhone));
-
+
$sPwd = isset($aValsToAdd[self::$FIELD_PASSWORD]) ? $aValsToAdd[self::$FIELD_PASSWORD] : $this->getCleanValue(self::$FIELD_PASSWORD);
$sSalt = genRndSalt();
$sPasswordHash = encryptUserPwd($sPwd, $sSalt);
- $aValsToAdd = array_merge($aValsToAdd, array (
- self::$FIELD_EMAIL => $sEmail,
+ return parent::insert(array_merge($aValsToAdd, [
+ self::$FIELD_EMAIL => $sEmail,
self::$FIELD_PASSWORD => $sPasswordHash,
+ self::$FIELD_PASSWORD_CHANGED => $iNow,
self::$FIELD_SALT => $sSalt,
- self::$FIELD_ADDED => time(),
- self::$FIELD_CHANGED => time(),
+ self::$FIELD_ADDED => $iNow,
+ self::$FIELD_CHANGED => $iNow,
self::$FIELD_IP => getVisitorIP(),
self::$FIELD_REFERRED => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
- self::$FIELD_PHONE => $sPhone,
- ));
- return parent::insert ($aValsToAdd, $isIgnore);
+ self::$FIELD_PHONE => $sPhone,
+ ]), $isIgnore);
}
- function update ($val, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+ function update ($val, $aValsToAdd = [], &$aTrackTextFieldsChanges = null)
{
- $sPwd = $this->getCleanValue(self::$FIELD_PASSWORD);
- if ($sPwd) {
+ $oDb = BxDolAccountQuery::getInstance();
+ $iNow = time();
+
+ $_aValsToAdd = [
+ self::$FIELD_CHANGED => $iNow
+ ];
+
+ if(($sPwd = $this->getCleanValue(self::$FIELD_PASSWORD))) {
+ $oDb->logPassword($val);
+
$sSalt = genRndSalt();
- $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
-
- $oAccount = BxDolAccount::getInstance($val, true);
- $iPasswordExpired = $oAccount->getPasswordExpiredDateByAccount($val);
-
- BxDolAccountQuery::getInstance()->logPassword($val);
- BxDolAccountQuery::getInstance()->updatePasswordExpired($val, $iPasswordExpired);
+ $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
+
+ $_aValsToAdd = array_merge($_aValsToAdd, [
+ self::$FIELD_PASSWORD => $sPasswordHash,
+ self::$FIELD_PASSWORD_CHANGED => $iNow,
+ self::$FIELD_SALT => $sSalt
+ ]);
}
- $aValsToAdd = array_merge(
- $aValsToAdd,
- array (self::$FIELD_CHANGED => time()),
- $sPwd ? array (self::$FIELD_PASSWORD => $sPasswordHash, self::$FIELD_SALT => $sSalt) : array()
- );
-
- $bResult = parent::update ($val, $aValsToAdd, $aTrackTextFieldsChanges);
-
- if ($bResult){
- $oAccount = BxDolAccount::getInstance($val, true);
- if ($oAccount) {
- $aAccountInfo = $oAccount->getInfo();
- /**
- * @hooks
- * @hookdef hook-account-change_receive_news 'account', 'change_receive_news' - hook after change receive_news parameter for account
- * - $unit_name - equals `system`
- * - $action - equals `change_receive_news`
- * - $object_id - not used
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `account_id` - [int] account id
- * - `old_value` - [bool] old value for receive_news parameter
- * - `new_value` - [bool] new value for receive_news parameter
- * - `email` - [string] account's email
- * @hook @ref hook-account-change_receive_news
- */
- bx_alert('account', 'change_receive_news', 0, false, array('account_id' => $val, 'old_value' => $aAccountInfo['receive_news'], 'new_value' => $this->getCleanValue('receive_news'), 'email' => $aAccountInfo['email']));
- }
+ $aInfoOld = $oDb->getInfoById($val);
+
+ $bResult = parent::update($val, array_merge($aValsToAdd, $_aValsToAdd), $aTrackTextFieldsChanges);
+ if($bResult) {
+ $aInfoNew = $oDb->getInfoById($val);
+
+ /**
+ * @hooks
+ * @hookdef hook-account-change_receive_news 'account', 'change_receive_news' - hook after change receive_news parameter for account
+ * - $unit_name - equals `system`
+ * - $action - equals `change_receive_news`
+ * - $object_id - not used
+ * - $sender_id - not used
+ * - $extra_params - array of additional params with the following array keys:
+ * - `account_id` - [int] account id
+ * - `old_value` - [bool] old value for receive_news parameter
+ * - `new_value` - [bool] new value for receive_news parameter
+ * - `email` - [string] account's email
+ * @hook @ref hook-account-change_receive_news
+ */
+ bx_alert('account', 'change_receive_news', 0, false, [
+ 'account_id' => $val,
+ 'old_value' => $aInfoOld['receive_news'],
+ 'new_value' => $aInfoNew['receive_news'],
+ 'email' => $aInfoNew['email']]
+ );
}
+
return $bResult;
}
- protected function genCustomInputAgreement ($aInput)
+ protected function genCustomInputAgreement ($aInput)
{
$oPermalink = BxDolPermalinks::getInstance();
return '' . _t('_sys_form_account_input_agreement_value', bx_absolute_url($oPermalink->permalink('page.php?i=terms')), bx_absolute_url($oPermalink->permalink('page.php?i=privacy'))) . '
';
}
-
+
protected function _setCustomError ($s)
{
$this->aInputs['do_submit']['error'] = $s;
diff --git a/template/scripts/BxBaseServiceAccount.php b/template/scripts/BxBaseServiceAccount.php
index 10e57df32c..3e64f9581b 100644
--- a/template/scripts/BxBaseServiceAccount.php
+++ b/template/scripts/BxBaseServiceAccount.php
@@ -836,14 +836,12 @@ public function resetPassword()
*/
public function generateUserNewPwd($iAccountId)
{
- $sPwd = genRndPwd(8, false);
+ $sPassword = genRndPwd(8, false);
$sSalt = genRndSalt();
- $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
-
- $oAccount = BxDolAccount::getInstance($iAccountId);
- $iPasswordExpired = $oAccount->getPasswordExpiredDateByAccount($iAccountId);
-
- $this->_oAccountQuery->updatePassword($sPasswordHash, $sSalt, $iAccountId, $iPasswordExpired);
+ $sPasswordHash = encryptUserPwd($sPassword, $sSalt);
+
+ $this->_oAccountQuery->logPassword($iAccountId);
+ $this->_oAccountQuery->updatePassword($sPasswordHash, $sSalt, $iAccountId);
/**
* @hooks
@@ -856,9 +854,11 @@ public function generateUserNewPwd($iAccountId)
* - `action` - [string] can be forgot_password/change_password or $sDisplayName (display name for current form)
* @hook @ref hook-account-edited
*/
- bx_alert('account', 'edited', $iAccountId, $iAccountId, array('action' => 'forgot_password'));
+ bx_alert('account', 'edited', $iAccountId, $iAccountId, [
+ 'action' => 'forgot_password'
+ ]);
- return $sPwd;
+ return $sPassword;
}
protected function _confirmEmail($sKey)