public function initialize($csrf = false)
    {
        $this->_tokenRequired = $csrf;
        if ($csrf) {
            // get current token value from session
            $currentToken = App::$Session->get('_csrf_token', false);
            // set new token value to session
            $newToken = Crypt::randomString(mt_rand(32, 64));
            App::$Session->set('_csrf_token', $newToken);
            // if request is submited for this model - try to validate input data
            if ($this->send()) {
                // token is wrong - update bool state
                if ($currentToken !== $this->getRequest('_csrf_token')) {
                    $this->_tokenOk = false;
                }
            }
            // set token data to display
            $this->_csrf_token = $newToken;
        }
    }
public function initialize($csrf = false)
    {
        $this->_tokenRequired = $csrf;
        if ($csrf) {
            // get current token value from session
            $currentToken = App::$Session->get('_csrf_token', false);
            // set new token value to session
            $newToken = Crypt::randomString(mt_rand(32, 64));
            App::$Session->set('_csrf_token', $newToken);
            // if request is submited for this model - try to validate input data
            if ($this->send()) {
                // token is wrong - update bool state
                if ($currentToken !== $this->getRequest('_csrf_token')) {
                    $this->_tokenOk = false;
                }
            }
            // set token data to display
            $this->_csrf_token = $newToken;
        }
    }
public function initialize ( $ csrf = false ) { $ this -> _tokenRequired = $ csrf ; if ( $ csrf ) { // get current token value from session $ currentToken = App :: $ Session -> get ( '_csrf_token' , false ) ; // set new token value to session $ newToken = Crypt :: randomString ( mt_rand ( 32 , 64 ) ) ; App :: $ Session -> set ( '_csrf_token' , $ newToken ) ; // if request is submited for this model - try to validate input data if ( $ this -> send ( ) ) { // token is wrong - update bool state if ( $ currentToken !== $ this -> getRequest ( '_csrf_token' ) ) { $ this -> _tokenOk = false ; } } // set token data to display $ this -> _csrf_token = $ newToken ; } }
Initialize validator. Set csrf protection token from request data if available.
@param bool $csrf
Initialize validator . Set csrf protection token from request data if available .