Skip to content

Commit

Permalink
Update framework/core/src/Forum/Controller/UnsubscribeActionControlle…
Browse files Browse the repository at this point in the history
…r.php

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
  • Loading branch information
imorland and SychO9 authored Sep 18, 2023
1 parent c20540d commit b0d688e
Showing 1 changed file with 0 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,21 @@ public function handle(Request $request): ResponseInterface
$token = Arr::get($parsedBody, 'token');
$userId = Arr::get($parsedBody, 'userId');

// Fetch the unsubscribe token record
/** @var UnsubscribeToken|null $unsubscribeRecord */
$unsubscribeRecord = UnsubscribeToken::where('user_id', $userId)
->where('token', $token)
->first();

// If record exists and has not been used before
if ($unsubscribeRecord && empty($unsubscribeRecord->unsubscribed_at)) {
// Mark as unsubscribed
$unsubscribeRecord->unsubscribed_at = Carbon::now();
$unsubscribeRecord->save();

// Update user preferences
/** @var User $user */
$user = User::find($userId);
$user->setNotificationPreference($unsubscribeRecord->email_type, 'email', false);
$user->save();
}

// Redirect back to the forum's home page after unsubscribing
return new RedirectResponse($this->url->to('forum')->base());
}
}

0 comments on commit b0d688e

Please sign in to comment.