imageplus / auth-scaffolding
为fortify创建认证视图
Requires
- inertiajs/inertia-laravel: ^0.2.12
- jenssegers/agent: ^2.6.4
- laravel/fortify: ^1.4
This package is auto-updated.
Last update: 2024-09-29 05:22:30 UTC
README
基于Laravel Fortify并使用InertiaJS、VueJS和Bootstrap构建的简单认证脚手架
入门
要安装此包,您必须运行
composer require imageplus/auth-scaffolding
安装包后,运行以下命令
php artisan imageplus:scaffold-auth
这将生成应用程序中的认证脚手架
该包需要某些npm包,因此在运行上述命令后,请运行 npm i
来安装所需的包
该包使用数据库会话驱动程序,因此要创建此表,请运行以下迁移 php artisan migrate
切换功能
Fortify的一些功能是可选的。您可以通过从位于 config/fortify.php
的功能数组中删除它们来禁用这些功能。您可以只删除其中的一些,也可以全部删除。
此包也有一些自己的自定义功能,可以在其配置文件位置 config/imageplus-auth-scaffolding.php
中禁用,但首先必须发布
双因素认证
默认情况下,此功能已在fortify中启用,但必须在User模型中添加TwoFactorAuthenticatable
特质才能启用此功能
电子邮件验证
要启用此功能,请在config/fortify.php
中取消注释Features::emailVerification()
行,并实现MustVerifyEmail
合约
路由
请使用ImagePlusAuthScaffolding类或配置文件而不是Fortify,因为自定义提供程序允许使用InertiaJS认证视图
视图配置在两个地方。
配置文件
首先必须使用以下命令发布
php artisan vendor:publish --tag=imageplus-auth-scaffolding-config
发布后,您可以更改数组值以使用您想要的Inertia组件
ImageplusAuthServiceProvider
可以通过删除ImageplusAuthScaffolding::useDefaultViews();
行并在Inertia视图中直接调用以下函数来更改此处的路由
ImageplusAuthScaffolding::loginView($view)
ImageplusAuthScaffolding::twoFactorChallengeView($view)
ImageplusAuthScaffolding::resetPasswordView(
$view,
function($request) {
return [
'token' => $request->route()->parameter('token')
];
}
);
ImageplusAuthScaffolding::registerView($view)
ImageplusAuthScaffolding::verifyEmailView($view)
ImageplusAuthScaffolding::confirmPasswordView($view)
ImageplusAuthScaffolding::requestPasswordResetLinkView($view)
请注意,可以作为第二个参数提供额外的数据,可以是数组或函数
更改登录视图
以下代码示例显示了如何更改登录视图。它将更改登录视图为位于Pages目录Auth文件夹中的Login组件,以及传递额外的prop foo
ImageplusAuthScaffolding::loginView('Auth/Login', ['foo' => 'bar'])
浏览器会话
启用logout-other-sessions功能后,该包可以登出用户的帐户的其他所有实例,但为此功能能够工作,必须启用\Illuminate\Session\Middleware\AuthenticateSession::class
中间件
其他帮助
此处找不到的信息可以在其他所需包的官方文档中找到