Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send event when deleting all sessions #3014

Closed
wants to merge 11 commits into from
Next Next commit
feat: send event when deleting all sessions
  • Loading branch information
christyjacob4 committed Mar 25, 2022
commit f73285a579aad5af332cd3e25a86c5e93263d2b1
7 changes: 3 additions & 4 deletions app/controllers/api/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@
$protocol = $request->getProtocol();
$sessions = $user->getAttribute('sessions', []);

$currentSession = [];
foreach ($sessions as $session) {/** @var Document $session */
$dbForProject->deleteDocument('sessions', $session->getId());

Expand All @@ -1815,6 +1816,7 @@
->addCookie(Auth::$cookieName . '_legacy', '', \time() - 3600, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
->addCookie(Auth::$cookieName, '', \time() - 3600, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
;
$currentSession = $session;
}
}

Expand All @@ -1823,10 +1825,7 @@
$numOfSessions = count($sessions);

$events
->setParam('eventData', $response->output(new Document([
'sessions' => $sessions,
'total' => $numOfSessions,
]), Response::MODEL_SESSION_LIST))
->setParam('eventData', $response->output($currentSession, Response::MODEL_SESSION))
;

$usage
Expand Down
6 changes: 6 additions & 0 deletions src/Appwrite/Messaging/Adapter/Realtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Utopia\Database\Document;
use Appwrite\Messaging\Adapter;
use Utopia\App;
use Utopia\CLI\Console;

class Realtime extends Adapter
{
Expand Down Expand Up @@ -129,6 +130,8 @@ public function hasSubscriber(string $projectId, string $role, string $channel =
*/
public static function send(string $projectId, array $payload, string $event, array $channels, array $roles, array $options = []): void
{
// Console::success('REALTIME');
// var_dump($projectId, $payload, $event, $channels, $roles, $options);
if (empty($channels) || empty($roles) || empty($projectId)) return;

$permissionsChanged = array_key_exists('permissionsChanged', $options) && $options['permissionsChanged'];
Expand Down Expand Up @@ -242,6 +245,7 @@ public static function convertChannels(array $channels, string $userId): array
*/
public static function fromPayload(string $event, Document $payload, Document $project = null, Document $collection = null, Document $bucket = null): array
{
Console::success("FROM PAYLOAD - $event");
$channels = [];
$roles = [];
$permissionsChanged = false;
Expand All @@ -251,6 +255,7 @@ public static function fromPayload(string $event, Document $payload, Document $p
case strpos($event, 'account.recovery.') === 0:
case strpos($event, 'account.sessions.') === 0:
case strpos($event, 'account.verification.') === 0:
var_dump($payload);
$channels[] = 'account';
$channels[] = 'account.' . $payload->getAttribute('userId');
$roles = ['user:' . $payload->getAttribute('userId')];
Expand Down Expand Up @@ -320,6 +325,7 @@ public static function fromPayload(string $event, Document $payload, Document $p
break;
}

var_dump($channels, $roles, $permissionsChanged, $projectId);
return [
'channels' => $channels,
'roles' => $roles,
Expand Down