public function it_can_login_a_user_and_rehash_password(User $user, Token $token)
 {
     $email = '*****@*****.**';
     $password = '******';
     $this->userRepository->getByEmailAddress(EmailAddress::get($email))->willReturn($user);
     $user->getPassword()->willReturn(password_hash($password, PASSWORD_BCRYPT, ['cost' => 4]));
     $user->setPassword(new Argument\Token\StringContainsToken('$2y$10$'))->willReturn($user);
     $this->userRepository->update($user)->shouldBeCalled();
     $this->tokenService->createTokenForUser($user)->willReturn($token);
     $this->login($email, $password)->shouldReturn($token);
 }
예제 #2
0
 public function login(string $email, string $password) : Token
 {
     try {
         $user = $this->getUserByEmail($email);
         $this->verifyPassword($user, $password);
         return $this->tokenService->createTokenForUser($user);
     } catch (\Throwable $exception) {
         if ($exception instanceof AuthException) {
             throw $exception;
         }
         $this->log(LogLevel::ERROR, $exception->getMessage());
         throw LoginFailedException::systemError($exception);
     }
 }