wp-kit / auth
A wp-kit组件,用于处理身份验证
Requires
- php: >=7.2
- illuminate/auth: ^6.0
- illuminate/cache: ^6.0
- illuminate/cookie: ^6.0
- illuminate/validation: ^6.0
- wp-kit/config: 2.*
- wp-kit/hashing: 2.*
- wp-kit/kernel: 1.*
- wp-kit/utils: 2.*
- wp-kit/wp-login-auth: 1.*
This package is not auto-updated.
Last update: 2024-09-21 21:16:54 UTC
README
这是一个处理身份验证的wp-kit组件。
wp-kit/auth
被构建为与Themosis
一起工作,因为目前Themosis
中还没有内置的身份验证中间件。然而,由于Themosis
中内置了illuminate/routing
,我们能够在Routes
和Route Groups
上运行Middleware
。
wp-kit/auth
通过提供与WordPress直接集成的UserProvider来实现与illuminate/auth
的兼容性,以进行用户身份验证。
wp-kit/auth
附带四种类型的Middleware
- 身份验证(Illuminate):auth
- 基本身份验证(Illuminate):auth.basic
- 启动会话(Illuminate):start_session
- 访客重定向(WP Kit):guest
- WP登录身份验证(WP Kit):auth.wp_login
wp-kit/auth
包含一个类似于wp-kit/foundation
的AuthenticatesUsers
特质,所以您可以在Controllers
中使用这个特质,这样就可以像在Laravel中使用传统表单身份验证一样。
安装
在Themosis
安装的根目录下通过Composer
安装
composer require "wp-kit/auth"
设置
添加服务提供者
只需在提供者和主题配置中注册服务提供者和外观即可
//inside theme/resources/config/providers.config.php return [ // WPKit\Auth\AuthServiceProvider::class // ];
添加配置文件
注意:在构建了
UserProvider
Guard之后,此操作将更改为类似于Laravel中找到的传统配置文件。
为wp-kit
组件安装配置文件的最佳方法是通过wp kit vendor:publish
命令。
首先,安装WP CLI,然后安装此组件,wp kit vendor:publish
将自动与wp-kit/utils
一起安装,安装后可以运行
wp kit vendor:publish
有关更多信息,请访问wp-kit/utils
。
或者,您可以将配置文件手动放置在您的theme/resources/config
目录中。
允许头部
如果使用 BasicAuth
中间件,请确保您将以下行添加到您的 .htaccess
文件中,以允许 Authorization
标头
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
用法
您可以在路由组或路由本身上激活 Middleware
在组上使用 Middleware
// inside themosis-theme/resources/providers/RoutingService.php namespace Theme\Providers; use Themosis\Facades\Route; use Themosis\Foundation\ServiceProvider; class RoutingService extends ServiceProvider { /** * Define theme routes namespace. */ public function register() { Route::group([ 'middleware' => [ 'start_session', 'auth', //'auth.basic', //'auth.wp_login', //'auth.token' ], 'namespace' => 'Theme\Controllers' ], function () { require themosis_path('theme.resources').'routes.php'; }); } }
在路由上使用 Middleware
// inside themosis-theme/resources/routes.php Route::get('home', function(Input $request) { return view('welcome'); })->middleware('auth.wp_login');
在控制器中使用 Traits
AuthenticatesUsers
trait 处理使用自定义表单登录用户的所有操作。
namespace Theme\Controllers; use Themosis\Route\BaseController; use WPKit\Auth\Traits\AuthenticatesUsers; use WPKit\Auth\Traits\ValidatesRequests; class LoginController extends Controller { /* |-------------------------------------------------------------------------- | Login Controller |-------------------------------------------------------------------------- | | This controller handles authenticating users for the application and | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | */ use AuthenticatesUsers, ValidatesRequests; /** * Where to redirect users after login. * * @var string */ protected $redirectTo = '/'; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('guest')->except('logout'); } }
请确保添加路由
// an example in routes.php Route::get('account', 'Example@showLoginForm'); Route::post('account', 'Example@login'); Route::get('logout', 'Example@logout');
请确保添加登录表单视图
<-- Inside resources/view/auth/login.php --> <?php foreach( $errors as $field => $error ) : ?> <strong>There was an error with field: <?php echo $field; ?></strong> <?php endforeach; ?> <form method="post"> <div> <label>Username</label> <input type="text" name="email" placeholder="Username" /> </div> <div> <label>Password</label> <input type="password" name="password" placeholder="Password" /> </div> <div> <input type="submit" value="Submit" /> </div> </form>
配置
请按照上述说明安装并学习默认的 配置文件 以了解如何使用此组件。
参与其中
要了解如何使用 wp-kit
的更多信息,请查看文档
任何帮助都受欢迎。该项目是开源的,我们鼓励您参与。您可以通过以下多种方式为项目做出贡献:
- 报告错误问题
- 建议功能
- 发送带有代码修复或功能的 pull request
- 在 GitHub 上关注项目
- 在您的社区中分享项目
有关为框架做出贡献的详细信息,请查看 贡献指南。
要求
Wordpress 4+
PHP 5.6+
许可证
wp-kit/auth 是在 MIT 许可下授权的开源软件。