定制 tourze/user-agreement-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tourze/user-agreement-bundle

最新稳定版本:1.0.2

Composer 安装命令:

composer require tourze/user-agreement-bundle

包简介

用户协议管理,支持协议签署、撤销等功能的 Symfony Bundle

README 文档

README

English | 中文

PHP Version Latest Version License Build Status Code Coverage Total Downloads

A Symfony bundle for managing user agreements, protocols, and consent records. This bundle provides comprehensive functionality for handling user terms of service, privacy policies, and user account deletion requests in compliance with data protection regulations.

Table of Contents

Features

  • Protocol Management: Create and manage different types of user agreements (registration, usage, privacy, marketing)
  • Consent Tracking: Record and track user agreement to protocols with IP tracking
  • Account Deletion: Handle user account deletion requests with different revocation types
  • Admin Interface: EasyAdmin integration for backend management
  • JSON-RPC API: Programmatic access to agreement functionality
  • GDPR Compliance: Built-in support for data protection requirements

Installation

composer require tourze/user-agreement-bundle

Add the bundle to your config/bundles.php:

return [
    // ...
    UserAgreementBundle\UserAgreementBundle::class => ['all' => true],
];

Configuration

Basic Configuration

Create config/packages/user_agreement.yaml:

user_agreement:
    enabled: true
    ip_tracking: true
    retention_period: 365  # days

Database Setup

Run the migrations to create required database tables:

php bin/console doctrine:migrations:migrate

Admin Interface

Enable EasyAdmin integration in config/packages/easy_admin.yaml:

easy_admin:
    entities:
        ProtocolEntity:
            class: UserAgreementBundle\Entity\ProtocolEntity
        AgreeLog:
            class: UserAgreementBundle\Entity\AgreeLog
        RevokeRequest:
            class: UserAgreementBundle\Entity\RevokeRequest

Quick Start

1. Create Protocol Entities

use UserAgreementBundle\Entity\ProtocolEntity;
use UserAgreementBundle\Enum\ProtocolType;

$protocol = new ProtocolEntity();
$protocol->setType(ProtocolType::PRIVACY);
$protocol->setTitle('Privacy Policy');
$protocol->setVersion('1.0');
$protocol->setContent('Your privacy policy content...');
$protocol->setRequired(true);
$protocol->setEffectiveTime(new \DateTimeImmutable());

$entityManager->persist($protocol);
$entityManager->flush();

2. Record User Agreement

use UserAgreementBundle\Entity\AgreeLog;

$agreeLog = new AgreeLog();
$agreeLog->setMemberId($user->getId());
$agreeLog->setProtocolId($protocol->getId());
$agreeLog->setValid(true);

$entityManager->persist($agreeLog);
$entityManager->flush();

3. Handle Deletion Requests

use UserAgreementBundle\Entity\RevokeRequest;
use UserAgreementBundle\Enum\RevokeType;

$revokeRequest = new RevokeRequest();
$revokeRequest->setUser($user);
$revokeRequest->setType(RevokeType::All);
$revokeRequest->setRemark('User requested account deletion');

$entityManager->persist($revokeRequest);
$entityManager->flush();

Advanced Usage

Custom Protocol Validation

use Symfony\Component\Validator\Constraints as Assert;

#[Assert\Callback]
public function validateProtocol(ExecutionContextInterface $context): void
{
    if ($this->type === ProtocolType::PRIVACY && empty($this->content)) {
        $context->buildViolation('Privacy policy content is required')
            ->atPath('content')
            ->addViolation();
    }
}

Event-Driven Architecture

use UserAgreementBundle\Event\AgreeProtocolEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class ProtocolSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            AgreeProtocolEvent::class => 'onProtocolAgreed',
        ];
    }

    public function onProtocolAgreed(AgreeProtocolEvent $event): void
    {
        // Custom logic when user agrees to protocol
        $protocol = $event->getProtocol();
        $user = $event->getUser();
        
        // Send confirmation email, log activity, etc.
    }
}

Service Integration

use UserAgreementBundle\Service\MemberService;

class MyService
{
    public function __construct(
        private MemberService $memberService,
    ) {}
    
    public function processUser(UserInterface $user): void
    {
        $memberId = $this->memberService->extractMemberId($user);
        // Process user agreement logic
    }
}

Protocol Types

  • MEMBER_REGISTER: User registration agreement
  • MEMBER_USAGE: User usage terms
  • PRIVACY: Privacy policy
  • SALE_PUSH: Marketing communications consent

Revocation Types

  • All: Complete account deletion
  • NO_NOTIFY: Keep profile but opt out of notifications
  • NOTIFY: Keep profile and allow notifications

JSON-RPC API

The bundle provides JSON-RPC procedures for external integration:

  • ApiAgreeSystemProtocol: Record user agreement to protocols
  • ApiGetSystemProtocolContent: Retrieve protocol content

Admin Interface

Access the admin interface through EasyAdmin:

  • Protocol management: /admin/protocol
  • Agreement logs: /admin/agree-log
  • Deletion requests: /admin/revoke-request

Compliance Features

  • IP Tracking: Automatically records IP addresses for audit trails
  • Version Control: Protocol versioning for regulatory compliance
  • Consent Records: Immutable logs of user agreements
  • Data Retention: Proper handling of user data deletion requests

Requirements

  • PHP 8.1+
  • Symfony 6.4+
  • Doctrine ORM 3.0+

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-14