1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 00:15:51 +02:00

Refactor password checker, add extender (#2176)

This commit is contained in:
Alexander Skvortsov
2021-02-22 17:08:36 -05:00
committed by GitHub
parent fa10d794a4
commit 509adf228a
5 changed files with 206 additions and 5 deletions

View File

@@ -38,6 +38,7 @@ class UserServiceProvider extends AbstractServiceProvider
{
$this->registerAvatarsFilesystem();
$this->registerDisplayNameDrivers();
$this->registerPasswordCheckers();
$this->app->singleton('flarum.user.group_processors', function () {
return [];
@@ -88,6 +89,19 @@ class UserServiceProvider extends AbstractServiceProvider
->give($avatarsFilesystem);
}
protected function registerPasswordCheckers()
{
$this->app->singleton('flarum.user.password_checkers', function () {
return [
'standard' => function (User $user, $password) {
if ($this->app->make('hash')->check($password, $user->password)) {
return true;
}
}
];
});
}
/**
* {@inheritdoc}
*/
@@ -97,12 +111,13 @@ class UserServiceProvider extends AbstractServiceProvider
User::addGroupProcessor(ContainerUtil::wrapCallback($callback, $this->app));
}
$events = $this->app->make('events');
User::setPasswordCheckers($this->app->make('flarum.user.password_checkers'));
User::setHasher($this->app->make('hash'));
User::setGate($this->app->makeWith(Access\Gate::class, ['policyClasses' => $this->app->make('flarum.policies')]));
User::setDisplayNameDriver($this->app->make('flarum.user.display_name.driver'));
$events = $this->app->make('events');
$events->listen(Saving::class, SelfDemotionGuard::class);
$events->listen(Registered::class, AccountActivationMailer::class);
$events->listen(EmailChangeRequested::class, EmailConfirmationMailer::class);