mirror of
https://github.com/flarum/core.git
synced 2025-02-25 11:43:19 +01:00
Add validation to forgot password email field. closes #776
This commit is contained in:
parent
bd50a23966
commit
1fbce0db33
@ -16,6 +16,8 @@ use Flarum\Core\Repository\UserRepository;
|
||||
use Flarum\Forum\UrlGenerator;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Mail\Mailer;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Contracts\Validation\ValidationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Mail\Message;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
@ -47,20 +49,33 @@ class RequestPasswordResetHandler
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var Factory
|
||||
*/
|
||||
protected $validatorFactory;
|
||||
|
||||
/**
|
||||
* @param UserRepository $users
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
* @param Mailer $mailer
|
||||
* @param UrlGenerator $url
|
||||
* @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->settings = $settings;
|
||||
$this->mailer = $mailer;
|
||||
$this->url = $url;
|
||||
$this->translator = $translator;
|
||||
$this->validatorFactory = $validatorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,7 +85,18 @@ class RequestPasswordResetHandler
|
||||
*/
|
||||
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) {
|
||||
throw new ModelNotFoundException;
|
||||
|
Loading…
x
Reference in New Issue
Block a user