Implemented oauth session revocation notification.

Reworked webhooks notifications constructors
This commit is contained in:
ErickSkrauch
2020-10-01 01:40:28 +03:00
parent b904d5d314
commit 5fc97fdd7a
13 changed files with 283 additions and 137 deletions

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace common\notifications;
use common\models\Account;
use Webmozart\Assert\Assert;
final class AccountDeletedNotification implements NotificationInterface {
private Account $account;
public function __construct(Account $account) {
Assert::notNull($account->deleted_at, 'Account must be deleted');
$this->account = $account;
}
public static function getType(): string {
return 'account.deletion';
}
public function getPayloads(): array {
return [
'id' => $this->account->id,
'uuid' => $this->account->uuid,
'username' => $this->account->username,
'email' => $this->account->email,
'registered' => date('c', $this->account->created_at),
'deleted' => date('c', $this->account->deleted_at),
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace common\notifications;
use common\models\Account;
final class AccountEditNotification implements NotificationInterface {
private Account $account;
private array $changedAttributes;
public function __construct(Account $account, array $changedAttributes) {
$this->account = $account;
$this->changedAttributes = $changedAttributes;
}
public static function getType(): string {
return 'account.edit';
}
public function getPayloads(): array {
return [
'id' => $this->account->id,
'uuid' => $this->account->uuid,
'username' => $this->account->username,
'email' => $this->account->email,
'lang' => $this->account->lang,
'isActive' => $this->account->status === Account::STATUS_ACTIVE,
'isDeleted' => $this->account->status === Account::STATUS_DELETED,
'registered' => date('c', (int)$this->account->created_at),
'changedAttributes' => $this->changedAttributes,
];
}
}

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace common\notifications;
interface NotificationInterface {
public static function getType(): string;
public function getPayloads(): array;
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace common\notifications;
use common\models\OauthSession;
use Webmozart\Assert\Assert;
final class OAuthSessionRevokedNotification implements NotificationInterface {
private OauthSession $oauthSession;
public function __construct(OauthSession $oauthSession) {
Assert::notNull($oauthSession->revoked_at, 'OAuth session must be revoked');
$this->oauthSession = $oauthSession;
}
public static function getType(): string {
return 'oauth2.session_revoked';
}
public function getPayloads(): array {
return [
'accountId' => $this->oauthSession->account_id,
'clientId' => $this->oauthSession->client_id,
'revoked' => date('c', $this->oauthSession->revoked_at),
];
}
}