issue#100 Support Nextcloud password_policy

This commit is contained in:
Marcin Łojewski
2019-02-17 18:51:26 +01:00
parent a2ca6eb579
commit f94def108b
2 changed files with 23 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased] ## [Unreleased]
### Added ### Added
- Users can confirm passwords - Users can confirm passwords
- Support Nextcloud password_policy
### Fixed ### Fixed
- Getting user display names backend - Getting user display names backend

View File

@@ -45,6 +45,8 @@ use OCP\User\Backend\IPasswordConfirmationBackend;
use OCP\User\Backend\IProvideAvatarBackend; use OCP\User\Backend\IProvideAvatarBackend;
use OCP\User\Backend\ISetDisplayNameBackend; use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend; use OCP\User\Backend\ISetPasswordBackend;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
/** /**
* The SQL user backend manager. * The SQL user backend manager.
@@ -89,6 +91,10 @@ final class UserBackend extends ABackend implements
* @var IConfig The config instance. * @var IConfig The config instance.
*/ */
private $config; private $config;
/**
* @var EventDispatcher The event dispatcher.
*/
private $eventDispatcher;
/** /**
* @var IUserAction[] The actions to execute. * @var IUserAction[] The actions to execute.
*/ */
@@ -104,10 +110,12 @@ final class UserBackend extends ABackend implements
* @param UserRepository $userRepository The user repository. * @param UserRepository $userRepository The user repository.
* @param IL10N $localization The localization service. * @param IL10N $localization The localization service.
* @param IConfig $config The config instance. * @param IConfig $config The config instance.
* @param EventDispatcher $eventDispatcher The event dispatcher.
*/ */
public function __construct( public function __construct(
$AppName, Cache $cache, ILogger $logger, Properties $properties, $AppName, Cache $cache, ILogger $logger, Properties $properties,
UserRepository $userRepository, IL10N $localization, IConfig $config UserRepository $userRepository, IL10N $localization, IConfig $config,
EventDispatcher $eventDispatcher
) { ) {
$this->appName = $AppName; $this->appName = $AppName;
$this->cache = $cache; $this->cache = $cache;
@@ -116,6 +124,7 @@ final class UserBackend extends ABackend implements
$this->userRepository = $userRepository; $this->userRepository = $userRepository;
$this->localization = $localization; $this->localization = $localization;
$this->config = $config; $this->config = $config;
$this->eventDispatcher = $eventDispatcher;
$this->actions = []; $this->actions = [];
$this->initActions(); $this->initActions();
@@ -492,6 +501,11 @@ final class UserBackend extends ABackend implements
return false; return false;
} }
$event = new GenericEvent($password);
$this->eventDispatcher->dispatch(
'OCP\PasswordPolicy::validate', $event
);
$user = $this->userRepository->findByUid($uid); $user = $this->userRepository->findByUid($uid);
if (!($user instanceof User)) { if (!($user instanceof User)) {
return false; return false;