This commit is contained in:
gr
2026-11-11 14:22:02 +08:00
parent 245618dcdc
commit a62311a8da
64878 changed files with 3747172 additions and 66 deletions
@@ -0,0 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台(PHP版)
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,可去除界面版权logo
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
// | github下载:https://github.com/likeshop-github/likeadmin
// | 访问官网:https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\auth;
use app\adminapi\{
logic\auth\RoleLogic,
lists\auth\RoleLists,
validate\auth\RoleValidate,
controller\BaseAdminController
};
/**
* 角色控制器
* Class RoleController
* @package app\adminapi\controller\auth
*/
class RoleController extends BaseAdminController
{
/**
* @notes 查看角色列表
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 11:49
*/
public function lists()
{
return $this->dataLists(new RoleLists());
}
/**
* @notes 添加权限
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 11:49
*/
public function add()
{
$params = (new RoleValidate())->post()->goCheck('add');
$res = RoleLogic::add($params);
if (true === $res) {
return $this->success('添加成功', RoleLogic::getReturnData(), 1, 1);
}
return $this->fail(RoleLogic::getError());
}
/**
* @notes 编辑角色
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 14:18
*/
public function edit()
{
$params = (new RoleValidate())->post()->goCheck('edit');
$res = RoleLogic::edit($params);
if (true === $res) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(RoleLogic::getError());
}
/**
* @notes 删除角色
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 14:18
*/
public function delete()
{
$params = (new RoleValidate())->post()->goCheck('del');
RoleLogic::delete($params['id']);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 查看角色详情
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2021/12/29 14:18
*/
public function detail()
{
$params = (new RoleValidate())->goCheck('detail');
$detail = RoleLogic::detail($params['id']);
return $this->data($detail);
}
/**
* @notes 获取角色数据
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/10/13 10:39
*/
public function all()
{
$result = RoleLogic::getAllData();
return $this->data($result);
}
}
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace app\adminapi\controller\identity;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\service\IdentityHospitalSsoService;
use app\common\service\JsonService;
use think\exception\HttpResponseException;
final class HospitalSsoController extends BaseAdminController
{
// The service authenticates the real source DB session; exchange authenticates its private PKCE ticket.
public array $notNeedLogin = ['issue', 'exchange'];
public function issue()
{
return $this->handoff('issue');
}
public function exchange()
{
return $this->handoff('exchange');
}
private function handoff(string $operation)
{
$headers = ['Cache-Control' => 'no-store', 'Referrer-Policy' => 'no-referrer'];
if (!$this->request->isPost()) { return JsonService::fail('请使用POST请求')->code(405)->header($headers); }
if ($this->request->get() !== []) { return JsonService::fail('请求包含不支持的字段')->header($headers); }
$origin = (string) $this->request->header('origin', '');
if ($operation === 'exchange' && (($origin !== '' && $origin !== $this->request->domain())
|| $this->request->header('sec-fetch-site', '') === 'cross-site')) {
return JsonService::fail('登录请求来源不合法')->header($headers);
}
try {
$service = new IdentityHospitalSsoService();
$result = $operation === 'issue'
? $service->issue((string) $this->request->header('token', ''), $this->request->post())
: $service->exchange($this->request->post());
return JsonService::data($result)->header($headers);
} catch (HttpResponseException $error) { return $error->getResponse()->header($headers); }
catch (\Throwable $error) { return JsonService::fail('医院登录暂时不可用,请稍后重试')->header($headers); }
}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace app\adminapi\controller\identity;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\service\IdentitySessionService;
use app\adminapi\validate\LoginValidate;
use app\common\service\JsonService;
/** 独立账号后台的个人会话接口,服务内部始终核验真实数据库会话。 */
class SessionController extends BaseAdminController
{
// 首次改密/待绑定企微时也必须可用;这里仅跳过旧门禁,绝不跳过服务内认证。
public array $notNeedLogin = ['login', 'verify', 'password', 'logout'];
public function verify()
{
if (!$this->request->isPost()) {
return JsonService::fail('请使用POST请求');
}
$params = $this->request->post();
if (array_diff(array_keys($params), ['account', 'password']) !== []
|| !is_string($params['account'] ?? null) || $params['account'] === '' || strlen($params['account']) > 4096
|| str_contains($params['account'], "\0") || !is_string($params['password'] ?? null)
|| $params['password'] === '' || strlen($params['password']) > 4096 || str_contains($params['password'], "\0")) {
return JsonService::fail('登录参数不合法');
}
$params = (new LoginValidate())->post()->goCheck('verify');
return $this->data(IdentitySessionService::verify($params));
}
public function login()
{
if (!$this->request->isPost()) {
return JsonService::fail('请使用POST请求');
}
// 沿用原限流与字段校验,服务仍须在账号锁内重验当前凭据。
$params = (new LoginValidate())->post()->goCheck();
return $this->data(IdentitySessionService::login($params));
}
public function password()
{
if (!$this->request->isPost()) {
return JsonService::fail('请使用POST请求');
}
IdentitySessionService::changePassword((string) $this->request->header('token', ''), $this->request->post());
return $this->success('密码修改成功,请重新登录');
}
public function logout()
{
if (!$this->request->isPost()) {
return JsonService::fail('请使用POST请求');
}
$params = $this->request->post();
if (array_diff(array_keys($params), ['all']) !== [] || !in_array($params['all'] ?? 0, [0, 1, '0', '1'], true)) {
return JsonService::fail('退出参数不合法');
}
IdentitySessionService::logout((string) $this->request->header('token', ''), (int) ($params['all'] ?? 0) === 1);
return $this->success('已退出登录');
}
}