Add event to allow custom user password validation

This commit is contained in:
Toby Zerner 2016-11-07 18:03:49 +10:30
parent a32cb1fede
commit 7b86f412f7
2 changed files with 43 additions and 0 deletions

View File

@ -15,6 +15,7 @@ use Flarum\Core\Access\Gate;
use Flarum\Core\Support\EventGeneratorTrait;
use Flarum\Core\Support\ScopeVisibilityTrait;
use Flarum\Database\AbstractModel;
use Flarum\Event\CheckUserPassword;
use Flarum\Event\ConfigureUserPreferences;
use Flarum\Event\PostWasDeleted;
use Flarum\Event\PrepareUserGroups;
@ -340,6 +341,12 @@ class User extends AbstractModel
*/
public function checkPassword($password)
{
$valid = static::$dispatcher->until(new CheckUserPassword($this, $password));
if ($valid !== null) {
return $valid;
}
return static::$hasher->check($password, $this->password);
}

View File

@ -0,0 +1,36 @@
<?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\Event;
use Flarum\Core\User;
class CheckUserPassword
{
/**
* @var User
*/
public $user;
/**
* @var string
*/
public $password;
/**
* @param User $user
* @param string $password
*/
public function __construct($user, $password)
{
$this->user = $user;
$this->password = $password;
}
}