bprs / user-bundle
此包已 废弃 且不再维护。未建议替代包。
简单的 Symfony Userbundle,带有 RESTful API 以在应用程序之间共享用户
此包尚未发布版本,信息有限。
README
简单、可扩展的 Symfony Userbundle,带有 RESTful API 以在应用程序之间共享用户
安装
在您的 composer.json 文件中,添加到 "require"
"require": { "bprs/user-bundle": "dev-master" }
(对于稳定版本,请检查最新的发布标签!)
在您的 routing.yml 中添加
bprs_user: resource: . type: bprs_user
您的 security.yml 需要知道如何使用 Bprs Users。以下是一个简单的示例
security: role_hierarchy: ROLE_ADMIN: ROLE_USER encoders: Bprs\UserBUndle\Entity\User: algorithm: bcrypt cost: 12 providers: database: entity: class: YouYourBundle:YourUser property: username firewalls: main: pattern: / http_basic: ~ form_login: login_path: bprs_user_login check_path: bprs_user_login_check default_target_path: intake_backend csrf_provider: form.csrf_provider default_target_path: /de logout: path: bprs_user_logout target: /de anonymous: ~ access_control: - { path: /backend, roles: ROLE_USER } - { path: /backend/admin, roles: ROLE_ADMIN}
最后,在您的 config.yml 中添加到 doctrine
doctrine: orm: resolve_target_entities: Bprs\UserBundle\Entity\BprsUserInterface: Your\YourBundle\Entity\YourUser bprs_user: class: "YourBundle\Entity\YourUser" mail: commandline_host: www.yourhost.com adress: yourbot@example.com name: yourbot permissions: - ROLE_BPRS_USER_BACKEND - ROLE_ADMIN - ROLE_USER # and whatever roles your application uses and a new created admin should have user_defaults: - ROLE_USER # and whatever roles a new created user should have
用法
扩展 BprsUser 实体
BprsUser 实体是一个 MappedSuperclass。
例如:创建您的期望用户实体如下
namespace You/YourBundle/Entity; use Bprs/UserBundle/Entity/User as BprsUser; use Doctrine\ORM\Mapping as ORM; /** * MyUser * * @ORM\Table() * @ORM\Entity */ class MyUser extends BprsUser { /** * @var string * @ORM\Column(name="foo", type="string", length=3) */ private $foo; /** and so on **/ }
就是这样。Doctrine 将处理其余部分并将两个实体合并到一个表中。
创建第一个管理员用户
# First (only 'needed' after a new installation or configuarion)
./app/console bprs:userbundle:warmup
./app/console bprs:userbundle:create_admin -1 yourname -2 your@email.com
预热命令将配置中 'permissions' 声明的所有角色添加到数据库中。
创建管理员账户将自动添加具有所有权限的管理员用户。如果您不希望普通用户能够访问应用程序的所有部分,请不要使用此方法创建普通用户!
此包的权限
ROLE_BPRS_USER_BACKEND -> 访问 UserController (CRUD)