/** * @param string $identity - email address * @param mixed $credentials - e.g. password string * * @return \Cms\Access\Auth\Result */ public function checkLogin($identity, $credentials) { if (is_null($identity) || is_null($credentials) || !is_string($credentials)) { return null; } try { // get user object $userBusiness = new User('User'); $user = $userBusiness->getByEmail($identity); // check credentials $ph = new PasswordHasher(); if (!$ph->validate($credentials, $user->getPassword())) { return null; } // create auth result and return it return $this->createSuccessAuthResult($user); } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, \Seitenbau\Log::DEBUG); return null; } }
/** * @test * @group integration */ public function optinForPasswordShouldSetNewPasswordAndRemoveOptinCode() { $formerLifetime = OptinTestHelper::changeConfiguredLifetime(\Orm\Entity\OptIn::MODE_PASSWORD, 0); $userId = 'USER-ren01gc0-b7a3-4599-b396-94c8bb6c10d9-USER'; $optinCode = 'f03bb65grbw'; $password = '******'; $optinRequest = sprintf('/user/optin/params/{"code":"%s","password":"******"}', $optinCode, $password); $this->dispatch($optinRequest); OptinTestHelper::changeConfiguredLifetime(\Orm\Entity\OptIn::MODE_PASSWORD, $formerLifetime); $response = new Response($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $optinDao = \Cms\Dao\Factory::get('Optin'); $userDao = \Cms\Dao\Factory::get('User'); $user = $userDao->getById($userId); $pH = new PasswordHasher(); $this->assertTrue($pH->validate($password, $user->getPassword())); try { $optinDao->getByCode($optinCode); $this->fail('An expected exception has not been raised.'); } catch (\Exception $e) { $this->assertInstanceOf('Cms\\Exception', $e); } }