feat: only send after first session

This commit is contained in:
loks0n
2024-07-16 13:01:23 +01:00
parent 612aa1421b
commit 67ec4b49ed
+13 -2
View File
@@ -223,7 +223,12 @@ $createSession = function (string $userId, string $secret, Request $request, Res
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed saving user to DB');
}
if ($project->getAttribute('auths', [])['sessionAlerts'] ?? false) {
$sessionAlertsEnabled = $project->getAttribute('auths', [])['sessionAlerts'] ?? false;
$isFirstSession = $dbForProject->count('sessions', [
Query::equal('userId', [$user->getId()]),
]) === 1;
if ($sessionAlertsEnabled && !$isFirstSession) {
sendSessionAlert($locale, $user, $project, $session, $queueForMails);
}
@@ -903,10 +908,16 @@ App::post('/v1/account/sessions/email')
->setParam('sessionId', $session->getId())
;
if ($project->getAttribute('auths', [])['sessionAlerts'] ?? false) {
$sessionAlertsEnabled = $project->getAttribute('auths', [])['sessionAlerts'] ?? false;
$isFirstSession = $dbForProject->count('sessions', [
Query::equal('userId', [$user->getId()]),
]) === 1;
if ($sessionAlertsEnabled && !$isFirstSession) {
sendSessionAlert($locale, $user, $project, $session, $queueForMails);
}
$response->dynamic($session, Response::MODEL_SESSION);
});