/** * {@inheritDoc} */ public function authenticate(Request $request, Response $response) { $result = parent::authenticate($request, $response); if (!$result) { // fail? try using "username" as "email" $this->_config['fields']['username'] = '******'; if (!empty($request->data['username'])) { $request->data['email'] = $request->data['username']; } $result = parent::authenticate($request, $response); } if ($result && !empty($request->data['remember'])) { $controller = $this->_registry->getController(); if (empty($controller->Cookie)) { $controller->loadComponent('Cookie'); } // user information array $user = json_encode($result); // used to check that user's info array is authentic $hash = Security::hash($user, 'sha1', true); $controller->Cookie->write('User.Cookie', json_encode(compact('user', 'hash'))); } return $result; }
/** * Constructor * * @param \Cake\Controller\ComponentRegistry $registry The Component registry * used on this request. * @param array $config Array of config to use. */ public function __construct(ComponentRegistry $registry, $config) { $this->config(['fields' => ['provider' => 'provider', 'provider_uid' => 'provider_uid', 'openid_identifier' => 'openid_identifier'], 'hauth_return_to' => null]); parent::__construct($registry, $config); }
/** * test applying settings in the constructor * * @return void */ public function testConstructor() { $object = new FormAuthenticate($this->Collection, ['userModel' => 'AuthUsers', 'fields' => ['username' => 'user', 'password' => 'password']]); $this->assertEquals('AuthUsers', $object->config('userModel')); $this->assertEquals(['username' => 'user', 'password' => 'password'], $object->config('fields')); }