0

我有一个 cakephp 2 应用程序。我在其中添加了 ssl,站点中有一个表单,其字段使用 JavaScript 填充,表单是使用 JavaScript 提交的。启用安全组件后,我无法提交网站。我知道原因是在这个表单中我没有在某些部分使用表单助手。我确信有一些方法可以绕过特定方法的安全组件。我尝试了很多,但它不起作用。

以下是代码。

应用程序/控制器/appcontroller.php

class AppController extends Controller {
      public $components = array('Session',
                                  'Auth'=> array(
                                  'authenticate' => `array('Form' =>array('fields'=>array('username' => 'email'))))`,
                                   'Acl'   ,

                                  'Email' => array('from' => 'donotreply@qpaper.in',    'sendAs' => 'html',
                 )
                                ,'Security'=> array( 'allowedControllers'=>array('tests','live_tests'),'allowedActions'=>array('taketest','create_test'))
                                                                );
      public $helpers            =   array('Html', 'Form','Session','Js');

    function beforeFilter() {
    Security::setHash('md5');
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginError = 'Invalid Username or Password.';
    $this->Auth->authError = "You are not authorized to access.";
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
    $this->Auth->authorize = 'Actions';
    $this->Auth->actionPath = 'Controllers/';


            $this->Security->blackHoleCallback = 'forceSSL';
            $this->Security->requireSecure();

}   
  public function forceSSL() {
        $this->redirect('https://' . env('SERVER_NAME') . $this->here);
    }

}

我在 appcontroller 中强制使用 https

我要使用的表单在一个名为 testcontroller 的控制器和一个名为 test 的方法中

感谢您的时间!

4

1 回答 1

2

如果您想尝试使用 apache config 来执行此操作。试试这个

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
于 2012-11-29T14:24:46.590 回答