r4nkt/laravel-saasparilla

一个具有见解的功能集合,使Laravel SaaS创建者的生活更加轻松。

v0.2.0 2021-05-07 13:09 UTC

This package is auto-updated.

Last update: 2024-09-07 22:30:02 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

一个具有见解的功能集合,使Laravel SaaS创建者的生活更加轻松。

此包是为了解决痛点而开发的,但也受到了Freek和他的关于删除不活跃用户和团队的博客文章的启发。

还应注意的是,它是基于另一个r4nkt 构建的,您也可以将其用于您的任何项目。

最后,重要的是要指出,此包受益于SpatieLaravel包骨架包

安装

您可以通过composer安装此包

composer require r4nkt/laravel-saasparilla

您可以使用以下命令发布和运行迁移

php artisan vendor:publish --provider="R4nkt\Saasparilla\SaasparillaServiceProvider" --tag="laravel-saasparilla-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="R4nkt\Saasparilla\SaasparillaServiceProvider" --tag="laravel-saasparilla-config"

这是已发布配置文件的内容

<?php

use App\Models\User;
use Illuminate\Auth\Events\Verified;
use R4nkt\Saasparilla\Actions\Default\CulledUnverifiedUserNotifier;
use R4nkt\Saasparilla\Actions\Default\DeleteUser;
use R4nkt\Saasparilla\Actions\Default\FindUnverifiedUsers;
use R4nkt\Saasparilla\Actions\Default\FindUsersReadyForDeletion;
use R4nkt\Saasparilla\Actions\Default\MarkUserForDeletion;
use R4nkt\Saasparilla\Actions\Default\UnmarkUserMarkedForDeletion;
use R4nkt\Saasparilla\Features;
use R4nkt\Saasparilla\Mail\CulledUnverifiedUserMail;

return [

    /**
     * Features (not yet complete):
     *  - cleans up unverified users (default/jetstream)
     *     - marking/notifying/unmarking
     *     - deleting
     *  - inactive users, aka unsubscribed/no-longer-on-trial users (default???/jetstream???)
     *     - marking/notifying/unmarking
     *     - deleting
     *  - inactive teams, aka unsubscribed/no-longer-on-trial teams (default???/jetstream???)
     *     - marking/notifying/unmarking
     *     - deleting
     *  - welcoming verified users
     */
    'features' => [

        /**
         * Cleans up unverified users:
         *  - finds users, marks them for deletion, and notifies them
         *  - unmarks users who verify email before grace period expires
         *  - deletes if still not verified after grace period expires
         */
        Features::cleansUpUnverifiedUsers([
            'tidier' => 'unverified-users',
            'unmark_on' => Verified::class,
        ]),

    ],

    'tidiers' => [
        /**
         * Culls unverified users and purges them after grace period expires.
         */
        'unverified-users' => [
            'culler' => 'unverified-users',
            'unmarker' => 'user-for-deletion',
            'handler' => 'purge-culled-users',
        ],
    ],

    'cullers' => [
        /**
         * Finds unverified users, marks them, and notifies them. Unmarks them
         * if/when they verify their email.
         */
        'unverified-users' => [
            'params' => [
                'finder' => 'unverified-users',
                'marker' => 'user-for-deletion',
                'notifier' => 'culled-unverified-user',
            ],
        ],
    ],

    'handlers' => [
        /**
         * Finds culled users and deletes them.
         */
        'purge-culled-users' => [
            'params' => [
                'finder' => 'users-ready-for-deletion',
                'task' => 'delete-user',
            ],
        ],
    ],

    'finders' => [
        /**
         * Finds users that have not verified their email.
         */
        'unverified-users' => [
            'class' => FindUnverifiedUsers::class,
            'params' => [
                'model' => User::class,
                'threshold' => 14,
            ],
        ],
        /**
         * Finds users that are marked for deletion.
         */
        'users-ready-for-deletion' => [
            'class' => FindUsersReadyForDeletion::class,
            'params' => [
                'model' => User::class,
            ],
        ],
    ],

    'markers' => [
        /**
         * Marks users for deletion, which will take place once the grace
         * period has expired.
         */
        'user-for-deletion' => [
            'class' => MarkUserForDeletion::class,
            'params' => [
                'grace' => 30,
            ],
        ],
    ],

    'notifiers' => [
        /**
         * Notifies unverified users that their accounts will be deleted once
         * the grace period has expired.
         */
        'culled-unverified-user' => [
            'class' => CulledUnverifiedUserNotifier::class,
            'params' => [
                'mailable' => CulledUnverifiedUserMail::class,
                'email_attribute' => 'email',
            ],
        ],
    ],

    'tasks' => [
        /**
         * Deletes the given user.
         */
        'delete-user' => [
            'class' => DeleteUser::class,
        ],
    ],

    'unmarkers' => [
        /**
         * Unmarks a user for deletion, effectively reversing the related
         * marker. Unless it's marked for deletion in some other context, it
         * will no longer be deleted.
         */
        'user-for-deletion' => [
            'class' => UnmarkUserMarkedForDeletion::class,
        ],
    ],

];

使用方法

要删除未验证的用户,请执行以下Artisan命令

php artisan saasparilla:cull-unverified-users

要删除准备删除的用户,请执行以下Artisan命令

php artisan saasparilla:delete-users-ready-for-deletion

已验证用户

默认情况下,Saasparilla配置为监听Laravel的Illuminate\Auth\Events\Verified事件。当事件被触发时,已验证的用户将被取消标记。(默认情况下,这不会影响之前未被标记为删除的用户。)

与团队一起删除Jetstream用户

如果您的项目使用Laravel Jetstream并且配置为使用团队,那么您可能需要更改配置,以便使delete-user任务使用R4nkt\Saasparilla\Actions\Jetstream\DeleteUser类。

测试

composer test

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全漏洞

请审查我们的安全策略以了解如何报告安全漏洞。

鸣谢

许可

MIT许可(MIT)。请参阅许可文件以获取更多信息。