Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/User/src/Handler/PostUserCreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
use Psr\Http\Server\RequestHandlerInterface;
use Throwable;

use function fclose;
use function fwrite;
use function json_encode;
use function stream_socket_client;

/**
* @phpstan-import-type CreateUserDataType from CreateUserInputFilter
*/
Expand Down Expand Up @@ -71,11 +76,16 @@
$user = $this->userService->saveUser($data);
$this->messenger->addSuccess(Message::USER_CREATED);
if ($user->hasEmail()) {
$body = $this->template->render('user::welcome', [
'config' => $this->config,
'user' => $user,
]);
$this->mailService->sendWelcomeMail($user, $body);
$client = stream_socket_client("tcp://localhost:8556", $errno, $errstr, 30);

if (! $client) {
echo "Error: $errstr ($errno)\n";
} else {
$data['userUuid'] = $user->getUuid()->toString();
fwrite($client, json_encode($data) . "\n");

fclose($client);
}
}

return new EmptyResponse(StatusCodeInterface::STATUS_CREATED);
Expand All @@ -87,14 +97,14 @@
]),
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY
);
} catch (MailException $exception) {

Check notice on line 100 in src/User/src/Handler/PostUserCreateHandler.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Redundant catch clause

Exception 'MailException' is never thrown in the corresponding 'try' block

Check notice on line 100 in src/User/src/Handler/PostUserCreateHandler.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Redundant catch clause

Exception 'MailException' is never thrown in the corresponding 'try' block
$this->logger->err('Send user welcome email', [
'error' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
]);
$this->messenger->addError(Message::mailNotSentTo($user->getEmail()));

Check failure on line 107 in src/User/src/Handler/PostUserCreateHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan 8.2-ubuntu-latest

Cannot call method getEmail() on Core\User\Entity\User|null.

Check failure on line 107 in src/User/src/Handler/PostUserCreateHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan 8.3-ubuntu-latest

Cannot call method getEmail() on Core\User\Entity\User|null.

Check failure on line 107 in src/User/src/Handler/PostUserCreateHandler.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Cannot call method getEmail() on Core\User\Entity\User|null.

Check failure on line 107 in src/User/src/Handler/PostUserCreateHandler.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Cannot call method getEmail() on Core\User\Entity\User|null.
return new EmptyResponse(StatusCodeInterface::STATUS_CREATED);
} catch (BadRequestException | ConflictException | NotFoundException $exception) {
return new HtmlResponse(
Expand Down
Loading