BxBaseFormConfirmPhone.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. bx_import('BxTemplFormView');
  10. class BxFormConfirmPhoneCheckerHelper extends BxDolFormCheckerHelper
  11. {
  12. /**
  13. * Check if key exists or wrong format
  14. */
  15. function checkPhoneUniq($s)
  16. {
  17. $s = trim($s);
  18. if(!preg_match("/^\+[0-9\s]*$/", $s)) {
  19. return _t('_sys_form_confirm_phone_input_phone_error_format');
  20. }
  21. $oAccount = BxDolAccount::getInstance();
  22. if ($oAccount) { // user is logged in
  23. $aAccountInfo = $oAccount->getInfo();
  24. if ($s == $aAccountInfo['phone']) // don't check phone for uniq, if it wasn't changed
  25. return true;
  26. }
  27. return BxDolAccountQuery::getInstance()->getIdByPhone($s) ? _t('_sys_form_confirm_phone_input_phone_error_not_unique') : true;
  28. }
  29. function checkCodeExist($s)
  30. {
  31. $s = trim($s);
  32. if($s == '') {
  33. return _t('_sys_form_confirm_phone_input_code_error_empty');
  34. }
  35. $oSession = BxDolSession::getInstance();
  36. return $oSession->getValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE) != $s ? _t('_sys_form_confirm_phone_input_code_error_invalid', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-phone') . '?step=1') : true;
  37. }
  38. }
  39. /**
  40. * Phone Confirmation Form.
  41. */
  42. class BxBaseFormConfirmPhone extends BxTemplFormView
  43. {
  44. public function __construct($aInfo, $oTemplate)
  45. {
  46. parent::__construct($aInfo, $oTemplate);
  47. }
  48. }
  49. /** @} */