Alex Trofimov 12 лет назад
Родитель
Сommit
0357413cd6

+ 2 - 1
modules/boonex/antispam/classes/BxAntispamAlertsResponse.php

@@ -23,7 +23,8 @@ class BxAntispamAlertsResponse extends BxDolAlertsResponse
             case 'check_login':
                 $oAlert->aExtras['error_msg'] = BxDolService::call('bx_antispam', 'check_login');
                 break;
-            case ''; // TODO: check join
+            case 'check_join'; 
+                $oAlert->aExtras['error_msg'] = BxDolService::call('bx_antispam', 'check_join', array($oAlert->aExtras['email'], &$oAlert->aExtras['approve']));
                 break;
         }
         

+ 1 - 5
modules/boonex/antispam/classes/BxAntispamModule.php

@@ -137,12 +137,10 @@ class BxAntispamModule extends BxDolModule
      * then it checks in DNS black lists (@see serviceIsIpDnsBlacklisted),
      * then it checks in StopForumSpam service (@see BxAntispamStopForumSpam).
      *
-     * TODO: if dnsbl_behaviour == approval, inform caller to set account to approval status on positive detection
-     *
      * @param $sCurIP IP to check, or empty for current IP
      * @return empty string - if join should be allowed, error message - if join should be blocked
      */
-    function serviceCheckJoin ($sEmail, $sIp = '') 
+    function serviceCheckJoin ($sEmail, &$bApproval, $sIp = '') 
     {
         $bJoinBlock = ('block' == $this->_oConfig->getAntispamOption('dnsbl_behaviour_join'));
         $bApproval = false;
@@ -169,8 +167,6 @@ class BxAntispamModule extends BxDolModule
                 $sErrorMsg = $this->getErrorMessageSpam();
         }
 
-        bx_alert('bx_antispam', 'check_join', bx_get_logged_profile_id(), 0, array('email' => $sEmail, 'ip' => $sIp, 'error_msg' => &$sErrorMsg));
-
         return $sErrorMsg;
     }
 

+ 2 - 1
modules/boonex/antispam/install/sql/enable.sql

@@ -189,5 +189,6 @@ INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `eval`) VALUES
 SET @iHandler := LAST_INSERT_ID();
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
-('account', 'check_login', @iHandler);
+('account', 'check_login', @iHandler),
+('account', 'check_join', @iHandler);
 

+ 1 - 1
template/scripts/BxBaseAccountForms.php

@@ -67,7 +67,7 @@ class BxBaseAccountForms extends BxDolProfileForms {
 
         // approve profile if auto-approval is enabled and profile status is 'pending'
         $sStatus = $oProfile->getStatus();
-        $isAutoApprove = true; // TODO: add setting option to auto-approve added data automatically
+        $isAutoApprove = $oForm->isSetPendingApproval() ? false : true; // TODO: add setting option to auto-approve added data automatically
         if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove)
             $oProfile->approve(BX_PROFILE_ACTION_AUTO);
 

+ 41 - 10
template/scripts/BxBaseFormAccount.php

@@ -10,19 +10,21 @@
 bx_import('BxTemplFormView');
 
 
-class BxFormAccountCheckerHelper extends BxDolFormCheckerHelper {
-
+class BxFormAccountCheckerHelper extends BxDolFormCheckerHelper 
+{
     /**
      * Password confirmation check.
      */
-    function checkPasswordConfirm ($s) {
+    function checkPasswordConfirm ($s) 
+    {
         return $s == bx_process_input(bx_get(BxTemplFormAccount::$FIELD_PASSWORD));
     }
 
     /**
      * Password confirmation check.
      */
-    function checkPasswordCurrent ($s) {
+    function checkPasswordCurrent ($s) 
+    {
 
         bx_import('BxDolAccount');
         $oAccount = BxDolAccount::getInstance();
@@ -37,7 +39,8 @@ class BxFormAccountCheckerHelper extends BxDolFormCheckerHelper {
     /**
      * Check if email is uniq.
      */
-    function checkEmailUniq ($s) {
+    function checkEmailUniq ($s) 
+    {
         if (!$this->checkEmail($s))
             return false;
 
@@ -60,18 +63,40 @@ class BxFormAccountCheckerHelper extends BxDolFormCheckerHelper {
 /**
  * Create/Edit Account Form.
  */
-class BxBaseFormAccount extends BxTemplFormView {
-
+class BxBaseFormAccount extends BxTemplFormView 
+{
     static $FIELD_PASSWORD = 'password';
     static $FIELD_SALT = 'salt';
     static $FIELD_ADDED = 'added';
     static $FIELD_CHANGED = 'changed';
 
-    public function __construct($aInfo, $oTemplate) {
+    protected $_bSetPendingApproval = false;
+
+    public function __construct($aInfo, $oTemplate) 
+    {
         parent::__construct($aInfo, $oTemplate);
     }
 
-    public function insert ($aValsToAdd = array(), $isIgnore = false) {
+    function isValid () 
+    {
+        if (!parent::isValid ())
+            return false;
+
+        $sErrorMsg = '';
+        bx_alert('account', 'check_join', 0, false, array('error_msg' => &$sErrorMsg, 'email' => $this->getCleanValue('email'), 'approve' => &$this->_bSetPendingApproval));
+        if ($sErrorMsg)
+            $this->_setCustomError ($sErrorMsg);
+
+        return $sErrorMsg ? false : true;
+    }    
+
+    public function isSetPendingApproval()
+    {
+        return $this->_bSetPendingApproval;
+    }
+
+    public function insert ($aValsToAdd = array(), $isIgnore = false) 
+    {
         $sPwd = $this->getCleanValue(self::$FIELD_PASSWORD);
         $sSalt = genRndSalt();
         $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
@@ -85,7 +110,8 @@ class BxBaseFormAccount extends BxTemplFormView {
         return parent::insert ($aValsToAdd, $isIgnore);
     }
 
-    function update ($val, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) {    
+    function update ($val, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) 
+    {
         $sPwd = $this->getCleanValue(self::$FIELD_PASSWORD);
         if ($sPwd) {
             $sSalt = genRndSalt();
@@ -99,6 +125,11 @@ class BxBaseFormAccount extends BxTemplFormView {
         );
         return parent::update ($val, $aValsToAdd, $aTrackTextFieldsChanges);
     }
+
+    protected function _setCustomError ($s)
+    {
+        $this->aInputs['do_submit']['error'] = $s;
+    }
 }
 
 /** @} */

+ 2 - 2
template/scripts/BxBaseFormLogin.php

@@ -30,7 +30,7 @@ class BxBaseFormLogin extends BxTemplFormView
             return false;
 
         $sErrorString = bx_check_password($this->getCleanValue('ID'), $this->getCleanValue('Password'), $this->getRole());
-        $this->_setLoginError ($sErrorString);
+        $this->_setCustomError ($sErrorString);
         return $sErrorString ? false : true;
     }    
 
@@ -58,7 +58,7 @@ class BxBaseFormLogin extends BxTemplFormView
         return isset($this->aInputs['ID']['error']) ? $this->aInputs['ID']['error'] : '';
     }
 
-    protected function _setLoginError ($s) 
+    protected function _setCustomError ($s) 
     {
         $this->aInputs['ID']['error'] = $s;
     }

+ 11 - 9
tests/units/modules/boonex/antispam/classes/BxAntispamModuleTest.php

@@ -101,20 +101,20 @@ class BxAntispamModuleTest extends BxDolTestCase
     {
         $any = $this->anything();
         return array(
-            array(true, $any, $any, $any, $any, false), // join is NOT allowed for blocked IPs
-            array(false, '', $any, $any, false, true), // join is allowed if IP isn't blocked, DNSBL checking disabled, not listed in StopForumSpam
-            array(false, 'on', 'approval', false, false, true), // join is allowed if IP isn't blocked and DNSBL enabled in "approval" mode, but not listed
-            array(false, 'on', 'block', false, false, true), // join is allowed if IP isn't blocked and DNSBL enabled in "block", but not listed
-            array(false, 'on', 'approval', true, false, true), // join is allowed if IP isn't blocked and DNSBL enabled in "approval" and IP listed
-            array(false, 'on', 'block', true, $any, false), // join is NOT allowed if IP isn't blocked and DNSBL enabled in "block" and IP listed
-            array(false, '', $any, $any, true, false), // join is NOT allowed if IP isn't blocked but listed in StopForumSpam
+            array(true, $any, $any, $any, $any, false, false), // join is NOT allowed for blocked IPs
+            array(false, '', $any, $any, false, false, true), // join is allowed if IP isn't blocked, DNSBL checking disabled, not listed in StopForumSpam
+            array(false, 'on', 'approval', false, false, false, true), // join is allowed if IP isn't blocked and DNSBL enabled in "approval" mode, but not listed
+            array(false, 'on', 'block', false, false, false, true), // join is allowed if IP isn't blocked and DNSBL enabled in "block", but not listed
+            array(false, 'on', 'approval', true, false, true, true), // join is allowed if IP isn't blocked and DNSBL enabled in "approval" and IP listed
+            array(false, 'on', 'block', true, $any, false, false), // join is NOT allowed if IP isn't blocked and DNSBL enabled in "block" and IP listed
+            array(false, '', $any, $any, true, false, false), // join is NOT allowed if IP isn't blocked but listed in StopForumSpam
         );
     }
 
     /**
      * @dataProvider providerForServiceCheckJoin
      */
-    public function testServiceCheckJoin($bIpBlocked, $sDnsblEnable, $sDnsblBehaviour, $bDnsblIpBlacklisted, $bStopForumSpamSpammer, $bResultEmptyString)
+    public function testServiceCheckJoin($bIpBlocked, $sDnsblEnable, $sDnsblBehaviour, $bDnsblIpBlacklisted, $bStopForumSpamSpammer, $bResultSetApprove, $bResultEmptyString)
     {
         // set different options
         $this->_oModule->_oConfig->setAntispamOption('dnsbl_enable', $sDnsblEnable);
@@ -149,7 +149,9 @@ class BxAntispamModuleTest extends BxDolTestCase
         }
 
         // empty string - no spam detected
-        $this->assertTrue($bResultEmptyString == ('' == $this->_oModule->serviceCheckJoin($this->_sSampleEmail, $this->_sSampleIP)));
+        $bSetApprove = false;
+        $this->assertTrue($bResultEmptyString == ('' == $this->_oModule->serviceCheckJoin($this->_sSampleEmail, $bSetApprove, $this->_sSampleIP)));
+        $this->assertTrue($bResultSetApprove == $bSetApprove);
     }
 
     public function providerForServiceCheckLogin()