protected function _tokenLogin(Request $request)
    {
        if (!empty($request->query['token'])) {
            $token = $request->query['token'];
            $Users = TableRegistry::get('User.Users');
            $exists = $Users
                ->find()
                ->select(['id', 'username'])
                ->where(['token' => $token, 'token_expiration <=' => time()])
                ->limit(1)
                ->first();

            if ($exists) {
                $user = $this->_findUser($exists->username);
                if (is_array($user)) {
                    $controller = $this->_registry->getController();
                    if (isset($user['password'])) {
                        unset($user['password']);
                    }
                    $controller->Auth->setUser($user);
                    $exists->updateToken();

                    return true;
                }
            }
        }

        return false;
    }
protected function _tokenLogin(Request $request)
    {
        if (!empty($request->query['token'])) {
            $token = $request->query['token'];
            $Users = TableRegistry::get('User.Users');
            $exists = $Users
                ->find()
                ->select(['id', 'username'])
                ->where(['token' => $token, 'token_expiration <=' => time()])
                ->limit(1)
                ->first();

            if ($exists) {
                $user = $this->_findUser($exists->username);
                if (is_array($user)) {
                    $controller = $this->_registry->getController();
                    if (isset($user['password'])) {
                        unset($user['password']);
                    }
                    $controller->Auth->setUser($user);
                    $exists->updateToken();

                    return true;
                }
            }
        }

        return false;
    }
protected function _tokenLogin ( Request $ request ) { if ( ! empty ( $ request -> query [ 'token' ] ) ) { $ token = $ request -> query [ 'token' ] ; $ Users = TableRegistry :: get ( 'User.Users' ) ; $ exists = $ Users -> find ( ) -> select ( [ 'id' , 'username' ] ) -> where ( [ 'token' => $ token , 'token_expiration <=' => time ( ) ] ) -> limit ( 1 ) -> first ( ) ; if ( $ exists ) { $ user = $ this -> _findUser ( $ exists -> username ) ; if ( is_array ( $ user ) ) { $ controller = $ this -> _registry -> getController ( ) ; if ( isset ( $ user [ 'password' ] ) ) { unset ( $ user [ 'password' ] ) ; } $ controller -> Auth -> setUser ( $ user ) ; $ exists -> updateToken ( ) ; return true ; } } } return false ; }
Tries to login user using token.

Token must be passed as a GET parameter named `token`, tokens looks as follow:

// <md5-hash> (length = 32)
5df9f63916ebf8528697b629022993e8

Tokens are consumables, the same token cannot be used twice to log in.

@param \Cake\Network\Request $request A request object
@return bool True if user was logged in using token, false otherwise
Tries to login user using token .