imanaging-document / zeus-user-bundle
Zeus 用户扩展包
v2.0
2022-06-01 15:29 UTC
Requires
- php: ^7.1.3
- doctrine/orm: ^2.8
- imanaging-document/api-communication-bundle: dev-master
- symfony/config: ^4.2 | ^5
- symfony/dependency-injection: ^4.2 | ^5
- symfony/http-kernel: ^4.2 | ^5
- symfony/security-core: ^5.2
- symfony/yaml: ^4.2 | ^5
Requires (Dev)
- symfony/browser-kit: ^4.2 | ^5
- symfony/framework-bundle: ^4.2 | ^5
- symfony/phpunit-bridge: ^4.2 | ^5
This package is auto-updated.
Last update: 2024-09-27 18:52:16 UTC
README
此扩展包允许不同 imanaging-document 应用程序同步角色、模块、用户,并在您的应用程序中记录 Zeus 用户。
它需要 imanaging-document/api-communication-bundle。
此扩展包不能在 imanaging-document 应用程序之外使用。
使用以下命令安装扩展包
$ composer require imanaging-document/zeus-user-bundle
配置
扩展包配置
您需要在 .env 或 .env.local 文件中设置 TYPE_APPLICATION
TYPE_APPLICATION: core
其中 "core" 是您应用程序的类型。
您必须创建一个 config/packages/imanaging_zeus_user.yaml 文件
imanaging_zeus_user: api_get_modules_path: ~ api_get_roles_path: ~
这些字段是必须的,并且必须以 "/" 开头。
Doctrine 配置
doctrine: orm: resolve_target_entities: Imanaging\ZeusUserBundle\Interfaces\UserInterface: App\Entity\User Imanaging\ZeusUserBundle\Interfaces\ConnexionStatutInterface: App\Entity\ConnexionStatut Imanaging\ZeusUserBundle\Interfaces\ConnexionInterface: App\Entity\Connexion Imanaging\ZeusUserBundle\Interfaces\ModuleInterface: App\Entity\Module Imanaging\ZeusUserBundle\Interfaces\RoleInterface: App\Entity\Role
您必须设置您想要使用的实体。
基本用法
获取同步和登录服务
use Imanaging\ZeusUserBundle\Synchronisation; use Imanaging\ZeusUserBundle\Login; class MyBeautifulService { private ... private $synchronisationService; private $loginService; private ... /** * ... * @param Synchronisation $synchronisationService * ... */ public function __construct(..., Synchronisation $synchronisationService, Login $loginService, ...){ ... $this->synchronisationService = $synchronisationService; $this->loginService = $loginService; ... } ... }
同步
$result = $this->synchronisationService->synchroniserModules(); if (is_array($result)){ $output->writeln("<fg=green>".$result['nb_module_updated']." modules ont etes mis a jour.</>"); $output->writeln("<fg=green>".$result['nb_module_added']." modules ont etes crees.</>"); $output->writeln("<fg=green>".$result['nb_module_deleted']." modules ont etes supprimees.</>"); } else { $output->writeln("<fg=red>La mise à jour des modules a échoué.</>"); } $result = $this->synchronisationService->synchroniserRoles(); if (is_array($result)){ $output->writeln("<fg=green>".$result['nb_role_updated']." roles ont etes mis a jour.</>"); $output->writeln("<fg=green>".$result['nb_role_added']." roles ont etes crees.</>"); } else { $output->writeln("<fg=red>La mise à jour des roles a échoué.</>"); } $result = $this->synchronisationService->synchroniserUsers(); if (is_array($result)){ $output->writeln("<fg=green>".$result['nb_user_updated']." utilisateurs ont etes mis a jour.</>"); $output->writeln("<fg=green>".$result['nb_user_added']." utilisateurs ont etes crees.</>"); } else { $output->writeln("<fg=red>La mise à jour des utilisateurs a échoué.</>"); }
登录
$user = $loginService->canLog("LOGIN", "P@SSW0RD", "127.0.0.1"); if ($user instanceof User){ if ($user->isUtilisateurZeus()) { $token = new UsernamePasswordToken($user, 'password', "secured_area", array('ROLE_USER')); } else { $token = new UsernamePasswordToken($user, $user->getPassword(), "secured_area", array('ROLE_USER')); } // Set the token $this->get("security.token_storage")->setToken($token); $event = new InteractiveLoginEvent($request, $token); $eventDispatcher->dispatch("security.interactive_login", $event); // Create connexion success history $loginService->createConnexion($user, $user->getLogin(), 'connexion_reussie'); ... }