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

New design for reset password view

This commit is contained in:
Toby Zerner
2017-11-29 12:52:49 +10:30
parent 479e44dd04
commit 9392e1bec3
7 changed files with 213 additions and 49 deletions

View File

@@ -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'));
}
}

View File

@@ -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]));
}

View File

@@ -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();

View File

@@ -0,0 +1,62 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* 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;
}
}