用于提供一個(gè)統(tǒng)一的用戶注冊(cè)、登錄、用戶中心功能,免去重復(fù)開(kāi)發(fā)的煩惱。
用戶中心支持添加自定義菜單,方便各個(gè)應(yīng)用插件在應(yīng)用中心擴(kuò)展功能。
支持登錄、注冊(cè)、用戶中心、頭像設(shè)置、密碼設(shè)置、密碼找回、郵件驗(yàn)證、短信驗(yàn)證等。
界面介于bootstrap4開(kāi)發(fā)
請(qǐng)?jiān)?webman-admin 插件市場(chǎng)安裝
請(qǐng)求http://127.0.0.1:8787/app/user
執(zhí)行命令php webman app-plugin:create foo
創(chuàng)建一個(gè)應(yīng)用插件foo
1、創(chuàng)建配置 plugin/foo/config/event.php
<?php
return [
// 當(dāng)渲染用戶中心左側(cè)邊欄時(shí)
'user.sidebar.render' => [
function (stdClass $object) {
$request = request();
$path = $request ? $request->path() : '';
$object->sidebars[] = [
'name' => '付費(fèi)信息',
'items' => [
['name' => '會(huì)員充值', 'url' => '/app/foo/charge', 'class' => $path === '/app/foo/charge' ? 'active' : ''],
['name' => '訂單信息', 'url' => '/app/foo/orders', 'class' => $path === '/app/foo/orders' ? 'active' : ''],
]
];
}
],
];
2、創(chuàng)建控制器 plugin/foo/app/controller/ChargeController.php
<?php
namespace plugin\foo\app\controller;
use support\Request;
class ChargeController
{
public function index()
{
return view('charge/index');
}
}
3、創(chuàng)建模板plugin/foo/app/view/charge/index.html
<!-- 頁(yè)面head頭 -->
<?=plugin\user\api\Template::header('AI助手充值')?>
<!-- 頂部導(dǎo)航 -->
<?=plugin\user\api\Template::nav()?>
<div class="container">
<div class="row">
<!-- 用戶中心左側(cè)菜單 -->
<?=plugin\user\api\Template::sidebar()?>
<!-- 頁(yè)面主體內(nèi)容 -->
<div class="col-md-9 col-12 pt-4" id="app">
<div class="mb-4 card bg-white border-0 shadow-sm" style="min-height:80vh;">
<div class="card-body">
<h5>用戶充值標(biāo)題</h5>
<div>充值內(nèi)容展示</div>
</div>
</div>
</div>
</div>
</div>
<!-- 頁(yè)面footer -->
<?=plugin\user\api\Template::footer()?>
訪問(wèn) http://127.0.0.1:8787/app/foo/charge
頁(yè)面效果如下
用戶模塊自帶鑒權(quán),如果某個(gè)控制器不需要鑒權(quán),可以參考如下方式設(shè)置。
class LoginController
{
/**
* 不需要登錄驗(yàn)證的方法
* @var string[]
*/
protected $noNeedLogin = ['index', 'logout'];
}
鑒權(quán)中間件在 plugin/user/api/Middleware.php
,中間件默認(rèn)只對(duì) plugin/user/app
下的控制器起作用,如果要在其它插件或者主項(xiàng)目使用,需要在對(duì)應(yīng)的config/middleware.php
配置文件添加配置。
use plugin\user\api\Middleware;
return [
'' => [
Middleware::class
]
];