mirror of
https://github.com/flarum/core.git
synced 2025-07-10 03:16:22 +02:00
Add validation to forgot password email field. closes #776
This commit is contained in:
committed by
Toby Zerner
parent
bd50a23966
commit
1fbce0db33
@ -16,6 +16,8 @@ use Flarum\Core\Repository\UserRepository;
|
|||||||
use Flarum\Forum\UrlGenerator;
|
use Flarum\Forum\UrlGenerator;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Illuminate\Contracts\Mail\Mailer;
|
use Illuminate\Contracts\Mail\Mailer;
|
||||||
|
use Illuminate\Contracts\Validation\Factory;
|
||||||
|
use Illuminate\Contracts\Validation\ValidationException;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Mail\Message;
|
use Illuminate\Mail\Message;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
@ -47,20 +49,33 @@ class RequestPasswordResetHandler
|
|||||||
*/
|
*/
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Factory
|
||||||
|
*/
|
||||||
|
protected $validatorFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param UserRepository $users
|
* @param UserRepository $users
|
||||||
* @param SettingsRepositoryInterface $settings
|
* @param SettingsRepositoryInterface $settings
|
||||||
* @param Mailer $mailer
|
* @param Mailer $mailer
|
||||||
* @param UrlGenerator $url
|
* @param UrlGenerator $url
|
||||||
* @param TranslatorInterface $translator
|
* @param TranslatorInterface $translator
|
||||||
|
* @param Factory $validatorFactory
|
||||||
*/
|
*/
|
||||||
public function __construct(UserRepository $users, SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator)
|
public function __construct(
|
||||||
{
|
UserRepository $users,
|
||||||
|
SettingsRepositoryInterface $settings,
|
||||||
|
Mailer $mailer,
|
||||||
|
UrlGenerator $url,
|
||||||
|
TranslatorInterface $translator,
|
||||||
|
Factory $validatorFactory
|
||||||
|
) {
|
||||||
$this->users = $users;
|
$this->users = $users;
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->mailer = $mailer;
|
$this->mailer = $mailer;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
|
$this->validatorFactory = $validatorFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +85,18 @@ class RequestPasswordResetHandler
|
|||||||
*/
|
*/
|
||||||
public function handle(RequestPasswordReset $command)
|
public function handle(RequestPasswordReset $command)
|
||||||
{
|
{
|
||||||
$user = $this->users->findByEmail($command->email);
|
$email = $command->email;
|
||||||
|
|
||||||
|
$validation = $this->validatorFactory->make(
|
||||||
|
compact('email'),
|
||||||
|
['email' => 'required|email']
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($validation->fails()) {
|
||||||
|
throw new ValidationException($validation);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->users->findByEmail($email);
|
||||||
|
|
||||||
if (! $user) {
|
if (! $user) {
|
||||||
throw new ModelNotFoundException;
|
throw new ModelNotFoundException;
|
||||||
|
Reference in New Issue
Block a user