BxBaseFormAccount.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxTemplFormView');
  10. class BxFormAccountCheckerHelper extends BxDolFormCheckerHelper {
  11. /**
  12. * Password confirmation check.
  13. */
  14. function checkPasswordConfirm ($s) {
  15. return $s == bx_process_input(bx_get(BxTemplFormAccount::$FIELD_PASSWORD));
  16. }
  17. /**
  18. * Password confirmation check.
  19. */
  20. function checkPasswordCurrent ($s) {
  21. bx_import('BxDolAccount');
  22. $oAccount = BxDolAccount::getInstance();
  23. if (!$oAccount)
  24. return false;
  25. $aInfo = $oAccount->getInfo();
  26. return $aInfo['password'] == encryptUserPwd($s, $aInfo['salt']);
  27. }
  28. /**
  29. * Check if email is uniq.
  30. */
  31. function checkEmailUniq ($s) {
  32. if (!$this->checkEmail($s))
  33. return false;
  34. bx_import('BxDolAccount');
  35. bx_import('BxDolPermalinks');
  36. $oAccount = BxDolAccount::getInstance();
  37. if ($oAccount) { // user is logged in
  38. $aAccountInfo = $oAccount->getInfo();
  39. if ($s == $aAccountInfo['email']) // don't check email for uniq, if it wasn't changed
  40. return true;
  41. return BxDolAccountQuery::getInstance()->getIdByEmail($s) ? _t('_sys_form_account_input_email_uniq_error_loggedin') : true;
  42. }
  43. return BxDolAccountQuery::getInstance()->getIdByEmail($s) ? _t('_sys_form_account_input_email_uniq_error', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password')) : true;
  44. }
  45. }
  46. /**
  47. * Create/Edit Account Form.
  48. */
  49. class BxBaseFormAccount extends BxTemplFormView {
  50. static $FIELD_PASSWORD = 'password';
  51. static $FIELD_SALT = 'salt';
  52. static $FIELD_ADDED = 'added';
  53. static $FIELD_CHANGED = 'changed';
  54. public function __construct($aInfo, $oTemplate) {
  55. parent::__construct($aInfo, $oTemplate);
  56. }
  57. public function insert ($aValsToAdd = array(), $isIgnore = false) {
  58. $sPwd = $this->getCleanValue(self::$FIELD_PASSWORD);
  59. $sSalt = genRndSalt();
  60. $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
  61. $aValsToAdd = array_merge($aValsToAdd, array (
  62. self::$FIELD_PASSWORD => $sPasswordHash,
  63. self::$FIELD_SALT => $sSalt,
  64. self::$FIELD_ADDED => time(),
  65. self::$FIELD_CHANGED => time(),
  66. ));
  67. return parent::insert ($aValsToAdd, $isIgnore);
  68. }
  69. function update ($val, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) {
  70. $sPwd = $this->getCleanValue(self::$FIELD_PASSWORD);
  71. if ($sPwd) {
  72. $sSalt = genRndSalt();
  73. $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
  74. }
  75. $aValsToAdd = array_merge(
  76. $aValsToAdd,
  77. array (self::$FIELD_CHANGED => time()),
  78. $sPwd ? array (self::$FIELD_PASSWORD => $sPasswordHash, self::$FIELD_SALT => $sSalt) : array()
  79. );
  80. return parent::update ($val, $aValsToAdd, $aTrackTextFieldsChanges);
  81. }
  82. }
  83. /** @} */