diff --git a/src/Forum/Controller/ResetPasswordController.php b/src/Forum/Controller/ResetPasswordController.php index 42a47b288..1e87fdf0c 100644 --- a/src/Forum/Controller/ResetPasswordController.php +++ b/src/Forum/Controller/ResetPasswordController.php @@ -26,18 +26,12 @@ class ResetPasswordController extends AbstractHtmlController */ protected $view; - /** - * @var TranslatorInterface - */ - protected $translator; - /** * @param Factory $view */ - public function __construct(Factory $view, TranslatorInterface $translator) + public function __construct(Factory $view) { $this->view = $view; - $this->translator = $translator; } /** @@ -55,10 +49,8 @@ class ResetPasswordController extends AbstractHtmlController throw new InvalidConfirmationTokenException; } - return $this->view->make('flarum::reset') - ->with('translator', $this->translator) + return $this->view->make('flarum.forum::reset-password') ->with('passwordToken', $token->id) - ->with('csrfToken', $request->getAttribute('session')->get('csrf_token')) - ->with('error', $request->getAttribute('session')->get('error')); + ->with('csrfToken', $request->getAttribute('session')->get('csrf_token')); } } diff --git a/src/Forum/Controller/SavePasswordController.php b/src/Forum/Controller/SavePasswordController.php index 0b36f9779..3a9fc4605 100644 --- a/src/Forum/Controller/SavePasswordController.php +++ b/src/Forum/Controller/SavePasswordController.php @@ -75,11 +75,12 @@ class SavePasswordController implements ControllerInterface $this->validator->assertValid(compact('password')); $validator = $this->validatorFactory->make($input, ['password' => 'required|confirmed']); + if ($validator->fails()) { throw new ValidationException($validator); } } catch (ValidationException $e) { - $request->getAttribute('session')->set('error', $e->errors()->first()); + $request->getAttribute('session')->set('errors', $e->errors()); return new RedirectResponse($this->url->toRoute('resetPassword', ['token' => $token->id])); } diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index 43f4c2bed..766cdc618 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -18,6 +18,8 @@ use Flarum\Event\SettingWasSet; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\Handler\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Settings\SettingsRepositoryInterface; +use Symfony\Component\Translation\TranslatorInterface; class ForumServiceProvider extends AbstractServiceProvider { @@ -44,6 +46,11 @@ class ForumServiceProvider extends AbstractServiceProvider $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum'); + $this->app->make('view')->share([ + 'translator' => $this->app->make(TranslatorInterface::class), + 'settings' => $this->app->make(SettingsRepositoryInterface::class) + ]); + $this->flushWebAppAssetsWhenThemeChanged(); $this->flushWebAppAssetsWhenExtensionsChanged(); diff --git a/src/Http/Middleware/ShareErrorsFromSession.php b/src/Http/Middleware/ShareErrorsFromSession.php new file mode 100644 index 000000000..4ab83d2f8 --- /dev/null +++ b/src/Http/Middleware/ShareErrorsFromSession.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Http\Middleware; + +use Illuminate\Support\ViewErrorBag; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Stratigility\MiddlewareInterface; + +/** + * Inspired by Illuminate\View\Middleware\ShareErrorsFromSession + * + * @author Taylor Otwell + */ +class ShareErrorsFromSession implements MiddlewareInterface +{ + /** + * @var ViewFactory + */ + protected $view; + + /** + * @param ViewFactory $view + */ + public function __construct(ViewFactory $view) + { + $this->view = $view; + } + + /** + * {@inheritdoc} + */ + public function __invoke(Request $request, Response $response, callable $out = null) + { + $session = $request->getAttribute('session'); + + // If the current session has an "errors" variable bound to it, we will share + // its value with all view instances so the views can easily access errors + // without having to bind. An empty bag is set when there aren't errors. + $this->view->share( + 'errors', $session->get('errors', new ViewErrorBag) + ); + + // Putting the errors in the view for every view allows the developer to just + // assume that some errors are always available, which is convenient since + // they don't have to continually run checks for the presence of errors. + + $session->remove('errors'); + + return $out ? $out($request, $response) : $response; + } +} + diff --git a/views/layouts/basic.blade.php b/views/layouts/basic.blade.php new file mode 100644 index 000000000..7143e24c9 --- /dev/null +++ b/views/layouts/basic.blade.php @@ -0,0 +1,106 @@ +{{-- TODO: Change below to @php when Laravel is upgraded --}} +get('theme_primary_color', '#000'); +?> + + + + + + {{-- TODO: Change below to @hasSection when Laravel is upgraded --}} + @if ($__env->hasSection('title')) @yield('title') - @endif{{ $settings->get('forum_title') }} + + + + + + +
+ @yield('content') +
+ + diff --git a/views/reset-password.blade.php b/views/reset-password.blade.php new file mode 100644 index 000000000..11ac7020e --- /dev/null +++ b/views/reset-password.blade.php @@ -0,0 +1,33 @@ +@extends('flarum.forum::layouts.basic') +@inject('url', 'Flarum\Forum\UrlGenerator') + +@section('title', $translator->trans('core.views.reset_password.title')) + +@section('content') + @if ($errors->any()) +
+ +
+ @endif + +
+ + + +

+ +

+ +

+ +

+ +

+ +

+
+@endsection diff --git a/views/reset.blade.php b/views/reset.blade.php deleted file mode 100644 index 671157b38..000000000 --- a/views/reset.blade.php +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - Reset Your Password - - - - - -

{{ $translator->trans('core.views.reset.title') }}

- - @if (! empty($error)) -

{{ $error }}

- @endif - -
- - - -

-
- -

- -

-
- -

- -

- -

-
- -