承接 chaplean/user-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chaplean/user-bundle

Composer 安装命令:

composer require chaplean/user-bundle

包简介

Creates a user account and log in (from FOSUserBundle)

README 文档

README

Prerequisites

This version of the bundle requires Symfony 3.4+.

Installation

1. Composer

composer require chaplean/user-bundle

2. AppKernel.php

Add

            new Chaplean\Bundle\UserBundle\ChapleanUserBundle(),
            new FOS\UserBundle\FOSUserBundle(),

NOTE: After SecurityBundle

3. Define User entity

Create a User class with doctrine information.

<?php
//...

use Chaplean\Bundle\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="<YourTableName>")
 */
class User extends BaseUser {
//...
}

4. Minimal Configuration

Define namespace your user entity in app/config/config.yml:

chaplean_user:
    entity:
        user:
            class: '<NamespaceUserEntity>'

Import default config in app/config/config.yml:

imports:
    - { resource: '@ChapleanUserBundle/Resources/config/config.yml' }

Define a route name for index path In app/config/config.yml:

chaplean_user:
    entity:
        user:
            class: '<NamespaceUserEntity>'
    controller:
        index_route: <YourRouteNameForIndex>
        login_route: <YourRouteNameForLogin>
        register_password_route: <Route to set password on register> # default: 'chaplean_user_password_set_password'
        resetting_password_route: <Route to set password on resetting> # default: null and use register_password_route

Custom templating email: In app/config/config.yml

chaplean_user:
    # ...
    emailing:
        register:
            subject: '<Translation key>'
            body: '<template twig>'
        resetting:
            subject: '<Translation key>'
            body: '<template twig>'

5. Configure security

In app/config/security.yml:

imports:
    - { resource: '@ChapleanUserBundle/Resources/config/security.yml' }

If you want you can also overide the defaults :

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    firewalls:
        main:
            pattern: ^/
            form_login:
                login_path: /login
                check_path: /api/login
                use_forward: false
                remember_me: true
                use_referer: true
                success_handler: chaplean_user.authentication.handler_json
                failure_handler: chaplean_user.authentication.handler_json
                csrf_token_generator: security.csrf.token_manager
            logout:
                path: /logout
                target: /
            anonymous:    true

6. Import routing.yml

You should then create a Controller action for your login page. Make this controller inherit LoginController to get the checkAction and logoutAction actions. Finally in your routing create a route for these.

In your controller:

<?php

namespace App\Bundle\FrontBundle\Controller;

use Chaplean\Bundle\UserBundle\Controller\LoginController as BaseController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\SecurityUtilityTest\Csrf\CsrfTokenManagerInterface;

/**
 * Class LoginController.
 */
class LoginController extends BaseController
{
    /**
     * @var CsrfTokenManagerInterface
     */
    protected $tokenManager;

    /**
     * LoginController constructor.
     *
     * @param CsrfTokenManagerInterface $tokenManager
     */
    public function __construct(CsrfTokenManagerInterface $tokenManager)
    {
        $this->tokenManager = $tokenManager;
    }

    /**
     * Renders the login page.
     *
     * @Route("/connexion-of")
     *
     * @return Response
     */
    public function loginAction()
    {
        return $this->render(
            'Login/login.html.twig',
            [
                'csrf_token' => $this->tokenManager->getToken('authenticate')->getValue()
            ]
        );
    }
}

In app/config/routing.yml:

chaplean_user_login_check:
    path: /api/login
    defaults: { _controller: AppFrontBundle:Login:check }
    methods: 'POST'

chaplean_user_logout:
    path: /logout
    defaults: { _controller: AppFrontBundle:Login:logout }

chaplean_user:
    resource: '@ChapleanUserBundle/Resources/config/routing.yml'

chaplean_user_api:
    type: rest
    resource: '@ChapleanUserBundle/Resources/config/routing_rest.yml'
    prefix:   /api/

app_front:
    type: annotation
    resource: '@AppFrontBundle/Controller/'
    prefix: /

Validator

MinimalPasswordRequirements

Chaplean\Bundle\UserBundle\Validator\Constraints\MinimalPasswordRequirements has 2 options:

  • minLength, default: 6
  • atLeastOneSpecialCharacter, default: true

Events

The UserBundle defines some events to allow you to hook in your own logic:

  • ChapleanUserCreatedEvent : Dispatched after a user is created. Use getUser() to retreive the entity.
  • ChapleanUserDeletedEvent : Dispatched before a user is deleted. Use getUser() to retreive the entity.

chaplean/user-bundle 适用场景与选型建议

chaplean/user-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 chaplean/user-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 chaplean/user-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 chaplean/user-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-10