public function getUser(Request $request)
{
if (!isset($this->_registry->Cookie) || !$this->_registry->Cookie instanceof CookieComponent) {
throw new \RuntimeException('CookieComponent is not loaded');
}
$cookieConfig = $this->_config['cookie'];
$cookieName = $this->_config['cookie']['name'];
unset($cookieConfig['name']);
$this->_registry->Cookie->configKey($cookieName, $cookieConfig);
$data = $this->_registry->Cookie->read($cookieName);
if (empty($data)) {
return false;
}
extract($this->_config['fields']);
if (empty($data[$username]) || empty($data[$password])) {
return false;
}
$user = $this->_findUser($data[$username], $data[$password]);
if ($user) {
$request->session()->write($this->_registry->Auth->sessionKey, $user);
return $user;
}
return false;
}