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
parent bdac88b573
commit c6c1ae32e6
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4

View File

@ -14,13 +14,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
@ -58,15 +56,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);