Example #1
0
 private function verifyPassword(User $user, string $password)
 {
     if (!password_verify($password, $user->getPassword())) {
         throw LoginFailedException::invalidCredentials();
     }
     if (password_needs_rehash($user->getPassword(), $this->algorithm, $this->passwordOptions)) {
         $user->setPassword(password_hash($password, $this->algorithm, $this->passwordOptions));
         $this->userRepository->update($user);
     }
 }
 public function it_can_rollBack_on_error_during_update_user(User $user)
 {
     $user->getUuid()->willReturn($uuid = Uuid::uuid4());
     $user->getEmailAddress()->willReturn(EmailAddress::get($email = '*****@*****.**'));
     $user->getPassword()->willReturn($password = password_hash('no.jedi.please', PASSWORD_BCRYPT));
     $user->getDisplayName()->willReturn($displayName = 'Nute Gunray');
     $this->pdo->beginTransaction()->shouldBeCalled();
     $exception = new \RuntimeException();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE users'))->willThrow($exception);
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow($exception)->duringUpdate($user);
 }
Example #3
0
 public function update(User $user)
 {
     $this->pdo->beginTransaction();
     try {
         $query = $this->executeSql('
             UPDATE users
                SET email_address = :email_address,
                    password = :password,
                    display_name = :display_name
              WHERE user_uuid = :user_uuid
         ', ['user_uuid' => $user->getUuid()->getBytes(), 'email_address' => $user->getEmailAddress()->toString(), 'password' => $user->getPassword(), 'display_name' => $user->getDisplayName()]);
         // When at least one of the fields changes, the rowCount will be 1 and an update occurred
         if ($query->rowCount() === 1) {
             $this->objectRepository->update(User::TYPE, $user->getUuid());
             $user->metaDataSetUpdateTimestamp(new \DateTimeImmutable());
         }
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
Example #4
0
 public function createTokenForUser(User $user)
 {
     $token = new Token(Uuid::uuid4(), $this->generatePassCode(), $user->getUuid(), $this->generateExpires());
     $this->tokenRepository->create($token);
     return $token;
 }
Example #5
0
 public function it_can_create_tokens_for_users(User $user)
 {
     $user->getUuid()->willReturn(Uuid::uuid4());
     $this->tokenRepository->create(new Argument\Token\TypeToken(Token::class))->shouldBeCalled();
     $this->createTokenForUser($user)->shouldHaveType(Token::class);
 }