net-pioneer/laravel-authplus

此包的最新版本(dev-master)没有可用的许可证信息。

laravel 多身份验证

dev-master 2021-12-15 08:48 UTC

This package is auto-updated.

Last update: 2024-09-15 14:35:37 UTC


README

基于 LiveWire 的 Laravel 多身份验证 v1.0.0
这是 Laravel 多身份验证的第一个版本,您可以验证多种类型的用户(管理员/客户/用户)。
net-pioneer (pouya)

注意
First Rival 是我的第一个项目,我决定将其发布供公众使用。所以如果我的代码中有什么问题,请自己修复并分享给我们 LOL。

功能
- 验证码
- 双因素认证(基于您的配置,如短信/电子邮件/谷歌身份验证器)
- 多身份验证
- 自动生成数据库表
- 用户验证(基本和简单验证)
-等等。
安装
composer require net-pioneer/laravel-authplus

或者将所有文件复制到您的项目目录下 Project-name/Packages/netpioneer/authplus
然后添加以下代码到您的 composer.json 文件中 "netpioneer\\authplus\\": "packages/netpioneer/authplus/src/"
"autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/",
            "netpioneer\\authplus\\": "packages/netpioneer/authplus/src/"
        }
    },

用法

1:
php artisan vendor:publish --provider=netpioneer\authplus\Providers\AuthplusServiceProvider
2:
php artisan migrate
注意:在运行迁移之前,您应该在 config 文件夹中配置 auth.php,如 guards、verifications 等。
3:
php artisan make:livewire Login
注意:您应该了解 LiveWire 的基础知识。我将简要介绍。
4:
视图
<form wire:submit.prevent="submit">
        @csrf
        @if(!$twofactor)
        <input type="text" name="username" wire:model.defer="username">
        <br>
        <input type="password" name="password" wire:model.defer="password">
        <br>
        <img src="/ap/ap_captcha?t={{time()}}" /><br>
        <input type="text" name="captcha" wire:model.defer="captcha">
        @else
        <input type="text" name="twofactor_input" wire:model.defer="twofactor_input">
        @endif
        <input type="submit">
    </form>

在 LiveWire 类内部

public function submit(){
        $guardName = 'admin';
        try {
            $this->res = app(AuthPlusAuthenticateUser::class)->twofactor($this->twofactor_input)->captcha($this->captcha)->Authenticate($guardName, $this->username, $this->password, true);
            $this->err = $this->res;
            return redirect()->away(AuthPlusLogics::getHomePage());
        }catch (LoginFailedExecption $exception){
            if($exception->getStatus() == LoginStatusEnum::TwoFactorRequired){
                $this->twofactor = true;
                $this->err = 'two factor';
            }else {
                $this->err = "login failed > " . $exception->getStatus() . " - data : " . (is_array($exception->getData()) ? implode(",",$exception->getData()) : $exception->getData());
            }
        }
    }

您可以在 Service Provider 中自定义您的身份验证功能,因为所有内容都是默认的

AuthPlus::AuthenticateMethod(AuthPlusAuthenticateUserDefualt::class);
AuthPlus::RedirectAuthenticated(AuthPlusRedirectAuthenticatedCustom::class);
AuthPlus::TwoFactorAuthenticator(AuthPlusTwoFactorSmsAuthenticator::class);

路由:如果 auth 配置文件中启用了开放路由,则不需要为每个路径创建路由,除了索引文件应该由您管理!

捐赠
好消息!如果您喜欢这个包,您可以通过向我捐赠 USDT 到我的钱包来支持我!一杯咖啡等。
USDT 钱包地址 (TRC20) : TBFJ3YirXc7vwwuRNeqhcBcQziB3h9bPbs