Bubble up exception for invalid confirmation token

This way, the error handler can simply be amended to deal with this
exception type with a dedicated error message or page.

Refs #1337.
Closes #1528.
This commit is contained in:
Franz Liedke 2019-08-14 19:45:54 +02:00 committed by Daniël Klabbers
parent 6e089c12d4
commit 5d768db6d2

View File

@ -12,13 +12,11 @@ namespace Flarum\Forum\Controller;
use Flarum\Foundation\Application;
use Flarum\Http\SessionAuthenticator;
use Flarum\User\Command\ConfirmEmail;
use Flarum\User\Exception\InvalidConfirmationTokenException;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Response\RedirectResponse;
class ConfirmEmailController implements RequestHandlerInterface
@ -56,15 +54,11 @@ class ConfirmEmailController implements RequestHandlerInterface
*/
public function handle(Request $request): ResponseInterface
{
try {
$token = Arr::get($request->getQueryParams(), 'token');
$token = Arr::get($request->getQueryParams(), 'token');
$user = $this->bus->dispatch(
new ConfirmEmail($token)
);
} catch (InvalidConfirmationTokenException $e) {
return new HtmlResponse('Invalid confirmation token');
}
$user = $this->bus->dispatch(
new ConfirmEmail($token)
);
$session = $request->getAttribute('session');
$this->authenticator->logIn($session, $user->id);