BxBaseServiceAccount.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System service for creating system profile functionality.
  11. */
  12. class BxBaseServiceAccount extends BxDol
  13. {
  14. protected $_oAccountForms;
  15. protected $_oAccountQuery;
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. $this->_oAccountForms = new BxTemplAccountForms();
  20. $this->_oAccountQuery = BxDolAccountQuery::getInstance();
  21. }
  22. /**
  23. * @page service Service Calls
  24. * @section bx_system_general System Services
  25. * @subsection bx_system_general-account Account
  26. * @subsubsection bx_system_general-create_account_form create_account_form
  27. *
  28. * @code bx_srv('system', 'create_account_form', [], 'TemplServiceAccount'); @endcode
  29. * @code {{~system:create_account_form:TemplServiceAccount[{"no_login_text":true, "no_auth_buttons":true}]~}} @endcode
  30. *
  31. * Join form.
  32. * @param $aParams array of additional params, such as:
  33. * - no_login_text
  34. * - no_auth_buttons
  35. *
  36. * @see BxBaseServiceAccount::serviceGetCreatePostForm
  37. */
  38. /**
  39. * @ref bx_system_general-create_account_form "create_account_form"
  40. */
  41. public function serviceCreateAccountForm ($aParams = array())
  42. {
  43. if (isLogged() && 'create-account' == bx_get('i')){
  44. header('Location: ' . BX_DOL_URL_ROOT);
  45. exit;
  46. }
  47. if (isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) { // remember referrer
  48. $sJoinReferrer = $_SERVER['HTTP_REFERER'];
  49. $aNoRelocatePages = array('forgot-password', 'login', 'create-account', 'logout');
  50. foreach ($aNoRelocatePages as $s) {
  51. if (false !== mb_stripos($sJoinReferrer, $s)) {
  52. $sJoinReferrer = '';
  53. break;
  54. }
  55. }
  56. if ($sJoinReferrer)
  57. BxDolSession::getInstance()->setValue('join-referrer', $sJoinReferrer);
  58. }
  59. $sLoginText = '';
  60. if (!isset($aParams['no_login_text']) || false === (bool)$aParams['no_login_text'])
  61. $sLoginText = '<hr class="bx-def-hr bx-def-margin-sec-topbottom" /><div>' . _t('_sys_txt_join_description', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=login')) . '</div>';
  62. $sAuth = '';
  63. if (!isset($aParams['no_auth_buttons']) || false === (bool)$aParams['no_auth_buttons'])
  64. $sAuth = BxDolService::call('system', 'member_auth_code', array(), 'TemplServiceLogin');
  65. return $sAuth . $this->_oAccountForms->createAccountForm($aParams) . $sLoginText;
  66. }
  67. public function serviceAccountSettingsEmail ($iAccountId = false)
  68. {
  69. if (false === $iAccountId)
  70. $iAccountId = getLoggedId();
  71. return $this->_oAccountForms->editAccountEmailSettingsForm($iAccountId);
  72. }
  73. public function serviceAccountSettingsPassword ($iAccountId = false)
  74. {
  75. if (false === $iAccountId)
  76. $iAccountId = getLoggedId();
  77. return $this->_oAccountForms->editAccountPasswordSettingsForm($iAccountId);
  78. }
  79. public function serviceAccountSettingsInfo ($iAccountId = false)
  80. {
  81. if (false === $iAccountId)
  82. $iAccountId = getLoggedId();
  83. return $this->_oAccountForms->editAccountInfoForm($iAccountId);
  84. }
  85. public function serviceAccountSettingsDelAccount ($iAccountId = false)
  86. {
  87. if (!$iAccountId)
  88. $iAccountId = bx_process_input(bx_get('id'), BX_DATA_INT);
  89. if (!$iAccountId)
  90. $iAccountId = getLoggedId();
  91. return $this->_oAccountForms->deleteAccountForm($iAccountId);
  92. }
  93. /**
  94. * Display unsubscribe from newsletters form
  95. */
  96. public function serviceUnsubscribeNews()
  97. {
  98. return $this->_unsubscribeForm('sys_unsubscribe_news');
  99. }
  100. /**
  101. * Display unsubscribe from notifications form
  102. */
  103. public function serviceUnsubscribeNotifications()
  104. {
  105. return $this->_unsubscribeForm('sys_unsubscribe_updates');
  106. }
  107. /**
  108. * Display confirmation statuses list
  109. */
  110. public function serviceGetConfirmationTypes()
  111. {
  112. $aResult = array();
  113. $aChoices = array(BX_ACCOUNT_CONFIRMATION_NONE, BX_ACCOUNT_CONFIRMATION_EMAIL, BX_ACCOUNT_CONFIRMATION_PHONE, BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE);
  114. foreach($aChoices as $sChoice)
  115. $aResult[$sChoice] = _t('_sys_acc_confirmation_type_' . $sChoice);
  116. return $aResult;
  117. }
  118. protected function _unsubscribeForm($sDisplay)
  119. {
  120. $iAccountId = bx_process_input(bx_get('id'));
  121. $sCode = bx_process_input(bx_get('code'));
  122. // validate input params
  123. $oAccount = BxDolAccount::getInstance($iAccountId);
  124. if (!$oAccount)
  125. return MsgBox(_t('_sys_txt_unsubscribe_wrong_link'));
  126. if ($sCode != $oAccount->getEmailHash())
  127. return MsgBox(_t('_sys_txt_unsubscribe_wrong_link'));
  128. $oForm = BxDolForm::getObjectInstance('sys_unsubscribe', $sDisplay);
  129. if (!$oForm)
  130. return MsgBox(_t('_sys_txt_unsubscribe_error_occured'));
  131. // show form
  132. $aAccountInfo = $oAccount->getInfo();
  133. $aAccountInfo['code'] = $sCode;
  134. $oForm->initChecker($aAccountInfo);
  135. if ($oForm->isSubmittedAndValid()) {
  136. if (!$oForm->update($oAccount->id()))
  137. return MsgBox(_t('_sys_txt_unsubscribe_error_occured'));
  138. return MsgBox(_t('_sys_txt_unsubscribe_email_settings_update_success'));
  139. }
  140. return '<div class="bx-def-padding-bottom">' . _t("_sys_txt_unsubscribe_info", $aAccountInfo['email']) . '</div>' . $oForm->getCode();
  141. }
  142. /**
  143. * Display email confirmation form, if confirmation code is provided then try to confirm profile
  144. */
  145. public function serviceEmailConfirmation($sMsg = false)
  146. {
  147. // if user is logged in and email is confirmed then just display a message
  148. if (isLogged()) {
  149. $oAccount = BxDolAccount::getInstance();
  150. if ($oAccount->isConfirmedEmail())
  151. return MsgBox(_t("_sys_txt_confirm_email_already_confirmed"));
  152. }
  153. // if confirmation code is provided in the URL - perform email confirmation right away
  154. if (bx_get('code') !== false)
  155. return $this->confirmEmail(bx_process_input(bx_get('code')));
  156. // if user requested to resend verification letter then send letter and display message
  157. if (bx_process_input(bx_get('resend')) && isLogged()) {
  158. $oAccount = BxDolAccount::getInstance();
  159. if ($oAccount->sendConfirmationEmail())
  160. $sMsg = _t('_sys_txt_confirm_email_sent');
  161. else
  162. $sMsg = _t('_sys_txt_confirm_email_sent_failed');
  163. return MsgBox($sMsg);
  164. }
  165. // show and process code verification form
  166. $oForm = BxDolForm::getObjectInstance('sys_confirm_email', 'sys_confirm_email');
  167. if (!$oForm)
  168. return MsgBox(_t("_sys_txt_confirm_email_error_occured"));
  169. $oForm->initChecker();
  170. if ($oForm->isSubmittedAndValid()) {
  171. $oKey = BxDolKey::getInstance();
  172. if (!$oKey)
  173. return MsgBox(_t("_sys_txt_confirm_email_error_occured"));
  174. else
  175. return $this->confirmEmail(trim($oForm->getCleanValue('code')));
  176. }
  177. return '<div class="bx-def-padding-sec-bottom">' . _t("_sys_txt_confirm_email_desc") . '</div>' . $oForm->getCode();
  178. }
  179. /**
  180. * Display phone confirmation forms, if confirmation code is provided then try to confirm profile
  181. */
  182. public function servicePhoneConfirmation($sMsg = false)
  183. {
  184. // if user is logged in and phone is confirmed then just display a message
  185. if (isLogged()) {
  186. $oAccount = BxDolAccount::getInstance();
  187. if ($oAccount->isConfirmedPhone())
  188. return MsgBox(_t("_sys_txt_confirm_phone_already_confirmed"));
  189. $iStep = 1;
  190. $a = $oAccount->getInfo();
  191. $sPhoneNumber = $a['phone'];
  192. $oSession = BxDolSession::getInstance();
  193. if ($sPhoneNumber != "" && $oSession->isValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE)){
  194. $iStep = 2;
  195. }
  196. if (bx_get('step'))
  197. $iStep = (int)bx_get('step');
  198. // show and process phone set form
  199. if ($iStep == 1){
  200. $oForm = BxDolForm::getObjectInstance('sys_confirm_phone', 'sys_confirm_phone_set_phone');
  201. if (!$oForm)
  202. return MsgBox(_t("_sys_txt_confirm_phone_set_phone_error_occured"));
  203. $oForm->initChecker(array('phone' => $sPhoneNumber));
  204. if ($oForm->isSubmittedAndValid()) {
  205. $oAccount->updatePhone(trim($oForm->getCleanValue('phone')));
  206. $sActivationCode = rand(1000, 9999);
  207. $sActivationText =_t('_sys_txt_confirm_phone_sms_text', $sActivationCode);
  208. $ret = null;
  209. bx_alert('account', 'before_confirm_phone_send_sms', $oAccount->id(), bx_get_logged_profile_id(), array('phone_number' => $sPhoneNumber, 'sms_text' => $sActivationText, 'override_result' => &$ret));
  210. if ($ret === null)
  211. {
  212. $oTwilio = BxDolTwilio::getInstance();
  213. if(!$oTwilio->sendSms($sPhoneNumber, $sActivationText)){
  214. return MsgBox(_t("_sys_txt_confirm_phone_send_sms_error_occured"));
  215. }
  216. }
  217. $oSession->setValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE, $sActivationCode);
  218. header('Location: ' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-phone'));
  219. }
  220. return '<div class="bx-def-padding-sec-bottom">' . _t("_sys_txt_confirm_phone_set_phone_desc_set_phone") . '</div>' .$oForm->getCode();
  221. }
  222. if ($iStep == 2){
  223. $oForm = BxDolForm::getObjectInstance('sys_confirm_phone', 'sys_confirm_phone_confirmation');
  224. if (!$oForm)
  225. return MsgBox(_t("_sys_txt_confirm_phone_set_phone_confirmation_occured"));
  226. $oForm->initChecker();
  227. if ($oForm->isSubmittedAndValid()) {
  228. $oAccount->updatePhoneConfirmed(true);
  229. $oSession->unsetValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE);
  230. return MsgBox(_t("_sys_txt_confirm_phone_confirm_success"));
  231. }
  232. return '<div class="bx-def-padding-sec-bottom">' . _t("_sys_txt_confirm_phone_set_phone_desc_phone_confirmation") . '</div>' .$oForm->getCode();
  233. }
  234. }
  235. }
  236. /**
  237. * Perform email confirmation
  238. */
  239. public function confirmEmail($sKey)
  240. {
  241. // check if key exists
  242. $oKey = BxDolKey::getInstance();
  243. if (!$oKey || !$oKey->isKeyExists($sKey))
  244. return MsgBox(_t("_sys_txt_confirm_email_error_occured"));
  245. // check if key data exists
  246. $aData = $oKey->getKeyData($sKey);
  247. if (!isset($aData['account_id']))
  248. return MsgBox(_t("_sys_txt_confirm_email_error_occured"));
  249. // check if account exists
  250. $oAccount = BxDolAccount::getInstance($aData['account_id']);
  251. if (!$oAccount)
  252. return MsgBox(_t("_sys_txt_confirm_email_error_occured"));
  253. // remove key
  254. $oKey->removeKey($sKey);
  255. // confirm email
  256. if (!$oAccount->updateEmailConfirmed(true))
  257. return MsgBox(_t("_sys_txt_confirm_email_error_occured"));
  258. // login to user's account automatically
  259. bx_login($aData['account_id']);
  260. // redirect with success message
  261. $sUrl = getParam('sys_redirect_after_email_confirmation');
  262. $oTemplate = BxDolTemplate::getInstance();
  263. $oTemplate->setPageNameIndex (BX_PAGE_TRANSITION);
  264. $oTemplate->setPageHeader (_t('_sys_txt_confirm_email_success'));
  265. $oTemplate->setPageContent ('page_main_code', MsgBox(_t('_sys_txt_confirm_email_success')));
  266. $oTemplate->setPageContent ('url_relocate', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($sUrl));
  267. BxDolTemplate::getInstance()->getPageCode();
  268. exit;
  269. }
  270. public function serviceGetOptionsResetPasswordRedirect()
  271. {
  272. $aResult = array();
  273. $aChoices = array('home', 'profile', 'profile_edit', 'custom');
  274. foreach($aChoices as $sChoice)
  275. $aResult[] = array('key' => $sChoice, 'value' => _t('_adm_stg_cpt_option_value_sys_account_reset_password_redirect_' . $sChoice));
  276. return $aResult;
  277. }
  278. /**
  279. * @page service Service Calls
  280. * @section bx_system_general System Services
  281. * @subsection bx_system_general-account Account
  282. * @subsubsection bx_system_general-forgot_password forgot_password
  283. *
  284. * @code bx_srv('system', 'forgot_password', [], 'TemplServiceAccount'); @endcode
  285. * @code {{~system:forgot_password:TemplServiceAccount~}} @endcode
  286. *
  287. * Display forgot password form,
  288. * if reset password key is provided then reset password
  289. *
  290. * @see BxBaseServiceAccount::serviceForgotPassword
  291. */
  292. /**
  293. * @ref bx_system_general-forgot_password "forgot_password"
  294. */
  295. public function serviceForgotPassword()
  296. {
  297. if(isLogged()){
  298. header('Location: ' . BX_DOL_URL_ROOT);
  299. exit;
  300. }
  301. if (bx_get('key') !== false)
  302. return $this->resetPassword();
  303. $oForm = BxDolForm::getObjectInstance('sys_forgot_password', 'sys_forgot_password');
  304. if (!$oForm)
  305. return '';
  306. $bNeedCheckEmailAndPhone = true;
  307. $sCaptionKey = "_sys_txt_forgot_pasword_by_both_desc";
  308. if (BxDolAccount::isNeedConfirmPhone()){
  309. if (!BxDolAccount::isNeedConfirmEmail()){
  310. unset($oForm->aInputs['email']);
  311. $sCaptionKey = "_sys_txt_forgot_pasword_by_phone_desc";
  312. $oForm->aInputs['phone']['checker']['func'] = 'PhoneExist';
  313. $bNeedCheckEmailAndPhone = false;
  314. }
  315. }
  316. else{
  317. unset($oForm->aInputs['phone']);
  318. $sCaptionKey = "_sys_txt_forgot_pasword_desc";
  319. $oForm->aInputs['email']['checker']['func'] = 'EmailExist';
  320. $bNeedCheckEmailAndPhone = false;
  321. }
  322. if ((BxDolAccount::isNeedConfirmPhone() && BxDolAccount::isNeedConfirmEmail())){
  323. if (isset($oForm->aInputs['phone']))
  324. $oForm->aInputs['phone']['required'] = false;
  325. if (isset($oForm->aInputs['email']))
  326. $oForm->aInputs['email']['required'] = false;
  327. }
  328. $oForm->initChecker();
  329. $bShowErrorEmptyBoth = false;
  330. if ($oForm->isSubmitted() && $bNeedCheckEmailAndPhone && $oForm->getCleanValue('phone') == '' && $oForm->getCleanValue('email') == ''){
  331. $bShowErrorEmptyBoth = true;
  332. $oForm->setValid(false);
  333. }
  334. if ($oForm->isSubmittedAndValid()) {
  335. $sEmail = $oForm->getCleanValue('email');
  336. $sPhone = $oForm->getCleanValue('phone');
  337. if (isset($oForm->aInputs['email']) && $sEmail != '') {
  338. $oAccount = BxDolAccount::getInstance($this->_oAccountQuery->getIdByEmail($sEmail));
  339. if($oAccount && $oAccount->sendResetPasswordEmail())
  340. $sResultMsg = MsgBox(_t("_sys_txt_forgot_pasword_check_email"));
  341. else
  342. $sResultMsg = MsgBox(_t("_sys_txt_forgot_pasword_email_send_failed"));
  343. $sForm = '';
  344. }
  345. if (isset($oForm->aInputs['phone']) && $sPhone != '') {
  346. $iAccountId = $this->_oAccountQuery->getIdByPhone($sPhone);
  347. $aAccountInfo = $this->_oAccountQuery->getInfoById($iAccountId);
  348. $sKey = bx_get_reset_password_key($aAccountInfo['email']);
  349. $sForgotPasswordUrl = bx_get_reset_password_link_by_key($sKey);
  350. $sSmsText = _t('_sys_txt_forgot_pasword_sms_text', $sForgotPasswordUrl);
  351. $mixedOverrideResult = null;
  352. bx_alert('account', 'before_forgot_password_send_sms', $aAccountInfo['id'], false, array('phone_number' => $sPhone, 'sms_text' => $sSmsText, 'override_result' => &$mixedOverrideResult));
  353. if ($mixedOverrideResult === null) {
  354. $oTwilio = BxDolTwilio::getInstance();
  355. if($oTwilio->sendSms($sPhone, $sSmsText))
  356. $sResultMsg = MsgBox(_t("_sys_txt_forgot_pasword_check_phone"));
  357. else
  358. $sResultMsg = MsgBox(_t("_sys_txt_forgot_pasword_error_occured"));
  359. }
  360. $sForm = '';
  361. }
  362. }
  363. else {
  364. $sResultMsg = _t($sCaptionKey);
  365. $sForm = $oForm->getCode();
  366. }
  367. return '<div class="bx-def-padding-sec-bottom">' . $sResultMsg . '</div>' . $sForm . ($bShowErrorEmptyBoth ? '<div class="bx-form-warn">' . _t("_sys_form_forgot_password_phone_and_email_empty_error") . '</div>' : '');
  368. }
  369. /**
  370. * @page service Service Calls
  371. * @section bx_system_general System Services
  372. * @subsection bx_system_general-account Account
  373. * @subsubsection bx_system_general-switch_profile switch_profile
  374. *
  375. * @code bx_srv('system', 'switch_profile', [123], 'TemplServiceAccount'); @endcode
  376. * @code {{~system:switch_profile:TemplServiceAccount:[123]~}} @endcode
  377. *
  378. * Switch current user profile.
  379. * User can switch between profiles if multiple profiles are created.
  380. * Also it's possible to switch to Organization profile if user is admin of Organization,
  381. * or other module which can `actAsProfile`.
  382. * Admin can switch to any prifile by default
  383. *
  384. * @param $iSwitchToProfileId profile ID to switch to
  385. * @return true on success or error message otherwise, so make sue to make strict (===) comparision
  386. *
  387. * @see BxBaseServiceAccount::serviceSwitchProfile
  388. */
  389. /**
  390. * @ref bx_system_general-switch_profile "switch_profile"
  391. */
  392. public function serviceSwitchProfile($iSwitchToProfileId)
  393. {
  394. $oProfile = BxDolProfile::getInstance($iSwitchToProfileId);
  395. if (!$oProfile) {
  396. return _t('_sys_txt_error_occured');
  397. }
  398. $iViewerAccountId = getLoggedId();
  399. $iSwitchToAccountId = $oProfile->getAccountId();
  400. $iViewerProfileId = bx_get_logged_profile_id();
  401. $aCheck = checkActionModule($iViewerProfileId, 'switch to any profile', 'system', false);
  402. $bAllowSwitchToAnyProfile = $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  403. $bCanSwitch = ($iSwitchToAccountId == $iViewerAccountId || $bAllowSwitchToAnyProfile);
  404. bx_alert('account', 'check_switch_context', $iSwitchToAccountId, $iViewerProfileId, array('switch_to_profile' => $iSwitchToProfileId, 'viewer_account' => $iViewerAccountId, 'override_result' => &$bCanSwitch));
  405. if (!$bCanSwitch) {
  406. return isset($aCheck[CHECK_ACTION_MESSAGE]) ? $aCheck[CHECK_ACTION_MESSAGE] : _t('_sys_txt_error_occured');
  407. }
  408. $oAccount = BxDolAccount::getInstance();
  409. if (!$oAccount->updateProfileContext($iSwitchToProfileId)) {
  410. return _t('_sys_txt_error_occured');
  411. }
  412. checkActionModule($iViewerProfileId, 'switch to any profile', 'system', true);
  413. return true;
  414. }
  415. /**
  416. * Reset password procedure
  417. */
  418. public function resetPassword()
  419. {
  420. $sKey = bx_process_input(bx_get('key'));
  421. $oForm = BxDolForm::getObjectInstance('sys_forgot_password', 'sys_forgot_password_reset');
  422. if(!empty($sKey) && isset($oForm->aInputs['key']))
  423. $oForm->aInputs['key']['value'] = $sKey;
  424. $oForm->initChecker();
  425. if($oForm->isSubmittedAndValid()) {
  426. $sErrorUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password');
  427. // check if key exists
  428. $oKey = BxDolKey::getInstance();
  429. $sKey = $oForm->getCleanValue('key');
  430. if(!$oKey || !$oKey->isKeyExists($sKey))
  431. return MsgBox(_t('_sys_txt_reset_pasword_error_invalid_key', $sErrorUrl));
  432. // check if key data exists
  433. $aKeyData = $oKey->getKeyData($sKey);
  434. if(empty($aKeyData['email']))
  435. return MsgBox(_t('_sys_txt_reset_pasword_error_invalid_key', $sErrorUrl));
  436. // check if account with such email exists
  437. $iAccountId = $this->_oAccountQuery->getIdByEmail($aKeyData['email']);
  438. if(empty($iAccountId))
  439. return MsgBox(_t('_sys_txt_reset_pasword_error_not_found', $sErrorUrl));;
  440. $sPassword = $oForm->getCleanValue('password');
  441. $sSalt = genRndSalt();
  442. if(!$this->_oAccountQuery->updatePassword(encryptUserPwd($sPassword, $sSalt), $sSalt, $iAccountId))
  443. return MsgBox(_t('_sys_txt_reset_pasword_error_occured', $sErrorUrl));;
  444. $this->_oAccountQuery->unlockAccount($iAccountId);
  445. $oKey->removeKey($sKey);
  446. return MsgBox(_t('_sys_txt_reset_pasword_success'), 3) . bx_srv('system', 'login_form_only', array('', bx_get_reset_password_redirect($iAccountId)), 'TemplServiceLogin');
  447. }
  448. return $oForm->getCode();
  449. }
  450. /**
  451. * Generate new password.
  452. */
  453. public function generateUserNewPwd($iAccountId)
  454. {
  455. $sPwd = genRndPwd(8, false);
  456. $sSalt = genRndSalt();
  457. $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
  458. $this->_oAccountQuery->updatePassword($sPasswordHash, $sSalt, $iAccountId);
  459. bx_alert('account', 'edited', $iAccountId, $iAccountId, array('action' => 'forgot_password'));
  460. return $sPwd;
  461. }
  462. }
  463. /** @} */