mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implemented oauth session revocation notification.
Reworked webhooks notifications constructors
This commit is contained in:
33
common/notifications/AccountDeletedNotification.php
Normal file
33
common/notifications/AccountDeletedNotification.php
Normal 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),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
37
common/notifications/AccountEditNotification.php
Normal file
37
common/notifications/AccountEditNotification.php
Normal 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,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
12
common/notifications/NotificationInterface.php
Normal file
12
common/notifications/NotificationInterface.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\notifications;
|
||||
|
||||
interface NotificationInterface {
|
||||
|
||||
public static function getType(): string;
|
||||
|
||||
public function getPayloads(): array;
|
||||
|
||||
}
|
30
common/notifications/OAuthSessionRevokedNotification.php
Normal file
30
common/notifications/OAuthSessionRevokedNotification.php
Normal 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),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user