[Jaws-commits] r12423 - trunk/jaws/html/gadgets/Users

afz at jaws-project.com afz at jaws-project.com
Mon Jan 16 09:49:01 UTC 2012


Author: afz
Date: 2012-01-16 09:49:01 +0000 (Mon, 16 Jan 2012)
New Revision: 12423

Modified:
   trunk/jaws/html/gadgets/Users/HTML.php
Log:
[Users]: compatible using captcha with new changes in Policy gadget

Modified: trunk/jaws/html/gadgets/Users/HTML.php
===================================================================
--- trunk/jaws/html/gadgets/Users/HTML.php	2012-01-16 09:48:29 UTC (rev 12422)
+++ trunk/jaws/html/gadgets/Users/HTML.php	2012-01-16 09:49:01 UTC (rev 12423)
@@ -46,18 +46,14 @@
 
         require_once JAWS_PATH . 'include/Jaws/Header.php';
         $request =& Jaws_Request::getInstance();
-        $post  = $request->get(array('email', 'captcha', 'captchaKey'), 'post');
+        $post  = $request->get(array('email'), 'post');
         $error = '';
 
-        $GLOBALS['app']->Registry->LoadFile('Policy');
-        $_captcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
-        if ($_captcha != 'DISABLED') {
-            require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $_captcha . '.php';
-            $captcha = new $_captcha();
-            if (!$captcha->Check()) {
-                $GLOBALS['app']->Session->PushSimpleResponse(_t('GLOBAL_CAPTCHA_ERROR_DOES_NOT_MATCH'), 'Users.ForgotLogin');
-                Jaws_Header::Location($this->GetURLFor('ForgotLogin'));
-            }
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        $resCheck = $mPolicy->CheckCaptcha();
+        if (Jaws_Error::IsError($resCheck)) {
+            $GLOBALS['app']->Session->PushSimpleResponse($resCheck->getMessage(), 'Users.ForgotLogin');
+            Jaws_Header::Location($this->GetURLFor('ForgotLogin'));
         }
 
         $model  = $GLOBALS['app']->LoadGadget('Users', 'Model');
@@ -118,19 +114,15 @@
         $tpl->SetVariable('email', _t('GLOBAL_EMAIL'));
         $tpl->SetVariable('remember', _t('GLOBAL_SUBMIT'));
 
-         $GLOBALS['app']->Registry->LoadFile('Policy');
-         $_captcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
-         if ($_captcha != 'DISABLED') {
-            require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $_captcha . '.php';
-            $captcha = new $_captcha();
-            $captchaRes = $captcha->Get();
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        if ($mPolicy->LoadCaptcha($captcha, $entry, $description)) {
             $tpl->SetBlock('forgot/captcha');
             $tpl->SetVariable('lbl_captcha', _t('GLOBAL_CAPTCHA_CODE'));
-            $tpl->SetVariable('captcha', $captchaRes['captcha']->Get());
-            if (!empty($captchaRes['entry'])) {
-                $tpl->SetVariable('captchavalue', $captchaRes['entry']->Get());
+            $tpl->SetVariable('captcha', $captcha);
+            if (!empty($entry)) {
+                $tpl->SetVariable('captchavalue', $entry);
             }
-            $tpl->SetVariable('captcha_msg', _t('GLOBAL_CAPTCHA_CODE_DESC'));
+            $tpl->SetVariable('captcha_msg', $description);
             $tpl->ParseBlock('forgot/captcha');
         }
 
@@ -468,8 +460,7 @@
         }
 
         $request =& Jaws_Request::getInstance();
-        $post = $request->get(array('user_language', 'user_theme', 'user_editor', 'user_timezone', 'captcha', 'captchaKey'),
-                              'post');
+        $post = $request->get(array('user_language', 'user_theme', 'user_editor', 'user_timezone'), 'post');
 
         $model = $GLOBALS['app']->LoadGadget('Users', 'Model');
         $result = $model->UpdatePreferences($GLOBALS['app']->Session->GetAttribute('user'),
@@ -612,22 +603,17 @@
         $result  = '';
         $request =& Jaws_Request::getInstance();
         $post = $request->get(array('username', 'email', 'nickname', 'password', 'password_check',
-                                    'fname', 'lname', 'gender', 'dob_year', 'dob_month', 'dob_day','url',
-                                    'captcha', 'captchaKey'),
+                                    'fname', 'lname', 'gender', 'dob_year', 'dob_month', 'dob_day','url'),
                               'post');
 
-        $GLOBALS['app']->Registry->LoadFile('Policy');
-        $_captcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
-        if ($_captcha != 'DISABLED') {
-            require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $_captcha . '.php';
-            $captcha = new $_captcha();
-            if (!$captcha->Check()) {
-                $result = _t('GLOBAL_CAPTCHA_ERROR_DOES_NOT_MATCH');
-            }
-        }
-
         require_once JAWS_PATH . 'include/Jaws/Header.php';
 
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        $resCheck = $mPolicy->CheckCaptcha();
+        if (Jaws_Error::IsError($resCheck)) {
+            $result = $resCheck->getMessage();
+        }
+
         if (empty($result)) {
             if ($post['password'] !== $post['password_check']) {
                 $result = _t('USERS_USERS_PASSWORDS_DONT_MATCH');
@@ -665,9 +651,7 @@
         // unset unnecessary registration data
         unset($post['password'],
               $post['password_check'],
-              $post['random_password'],
-              $post['captcha'],
-              $post['captchaKey']);
+              $post['random_password']);
         $GLOBALS['app']->Session->PushSimpleResponse($post, 'Users.Register.Data');
 
         Jaws_Header::Location($this->GetURLFor('Registration'));
@@ -738,21 +722,18 @@
             }
 
             $tpl->SetVariable('register', _t('USERS_REGISTER'));
-            $GLOBALS['app']->Registry->LoadFile('Policy');
-            $_captcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
-            if ($_captcha != 'DISABLED') {
-                require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $_captcha . '.php';
-                $captcha = new $_captcha();
-                $captchaRes = $captcha->Get();
+            $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+            if ($mPolicy->LoadCaptcha($captcha, $entry, $description)) {
                 $tpl->SetBlock('register/captcha');
                 $tpl->SetVariable('lbl_captcha', _t('GLOBAL_CAPTCHA_CODE'));
-                $tpl->SetVariable('captcha', $captchaRes['captcha']->Get());
-                if (!empty($captchaRes['entry'])) {
-                    $tpl->SetVariable('captchavalue', $captchaRes['entry']->Get());
+                $tpl->SetVariable('captcha', $captcha);
+                if (!empty($entry)) {
+                    $tpl->SetVariable('captchavalue', $entry);
                 }
-                $tpl->SetVariable('captcha_msg', _t('GLOBAL_CAPTCHA_CODE_DESC'));
+                $tpl->SetVariable('captcha_msg', $description);
                 $tpl->ParseBlock('register/captcha');
             }
+
             if ($response = $GLOBALS['app']->Session->PopSimpleResponse('Users.Register')) {
                 $tpl->SetBlock('register/response');
                 $tpl->SetVariable('msg', $response);



More information about the Jaws-commits mailing list