1
0
mirror of https://github.com/flarum/core.git synced 2025-08-02 22:47:33 +02:00

Generate URL in the controller instead of the view

This commit is contained in:
Toby Zerner
2017-11-29 22:20:06 +10:30
parent 1ef9217f4d
commit 5b46ec801d
2 changed files with 8 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ namespace Flarum\Forum\Controller;
use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Core\Access\AssertPermissionTrait;
use Flarum\Event\UserLoggedOut; use Flarum\Event\UserLoggedOut;
use Flarum\Forum\UrlGenerator;
use Flarum\Foundation\Application; use Flarum\Foundation\Application;
use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\Exception\TokenMismatchException; use Flarum\Http\Exception\TokenMismatchException;
@@ -55,9 +56,9 @@ class LogOutController implements ControllerInterface
protected $view; protected $view;
/** /**
* @var SettingsRepositoryInterface * @var UrlGenerator
*/ */
protected $settings; protected $url;
/** /**
* @param Application $app * @param Application $app
@@ -65,7 +66,6 @@ class LogOutController implements ControllerInterface
* @param SessionAuthenticator $authenticator * @param SessionAuthenticator $authenticator
* @param Rememberer $rememberer * @param Rememberer $rememberer
* @param Factory $view * @param Factory $view
* @param SettingsRepositoryInterface $settings
*/ */
public function __construct( public function __construct(
Application $app, Application $app,
@@ -73,14 +73,14 @@ class LogOutController implements ControllerInterface
SessionAuthenticator $authenticator, SessionAuthenticator $authenticator,
Rememberer $rememberer, Rememberer $rememberer,
Factory $view, Factory $view,
SettingsRepositoryInterface $settings UrlGenerator $url
) { ) {
$this->app = $app; $this->app = $app;
$this->events = $events; $this->events = $events;
$this->authenticator = $authenticator; $this->authenticator = $authenticator;
$this->rememberer = $rememberer; $this->rememberer = $rememberer;
$this->view = $view; $this->view = $view;
$this->settings = $settings; $this->url = $url;
} }
/** /**
@@ -106,9 +106,7 @@ class LogOutController implements ControllerInterface
if (array_get($request->getQueryParams(), 'token') !== $csrfToken) { if (array_get($request->getQueryParams(), 'token') !== $csrfToken) {
$view = $this->view->make('flarum.forum::log-out') $view = $this->view->make('flarum.forum::log-out')
->with('csrfToken', $csrfToken) ->with('url', $this->url->toRoute('logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : ''));
->with('forumTitle', $this->settings->get('forum_title'))
->with('return', array_get($request->getQueryParams(), 'return'));
return new HtmlResponse($view->render()); return new HtmlResponse($view->render());
} }

View File

@@ -1,13 +1,12 @@
@extends('flarum.forum::layouts.basic') @extends('flarum.forum::layouts.basic')
@inject('url', 'Flarum\Forum\UrlGenerator')
@section('title', $translator->trans('core.views.log_out.title')) @section('title', $translator->trans('core.views.log_out.title'))
@section('content') @section('content')
<p>{{ $translator->trans('core.views.log_out.log_out_confirmation', ['{forum}' => $forumTitle]) }}</p> <p>{{ $translator->trans('core.views.log_out.log_out_confirmation', ['{forum}' => $settings->get('forum_title')]) }}</p>
<p> <p>
<a href="{{ $url->toRoute('logout') }}?token={{ $csrfToken }}@if ($return)&return={{ urlencode($return) }}@endif" class="button"> <a href="{{ $url }}" class="button">
{{ $translator->trans('core.views.log_out.log_out_button') }} {{ $translator->trans('core.views.log_out.log_out_button') }}
</a> </a>
</p> </p>