更新
This commit is contained in:
@@ -52,7 +52,7 @@ class RoleController extends BaseAdminController
|
||||
$params = (new RoleValidate())->post()->goCheck('add');
|
||||
$res = RoleLogic::add($params);
|
||||
if (true === $res) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
return $this->success('添加成功', RoleLogic::getReturnData(), 1, 1);
|
||||
}
|
||||
return $this->fail(RoleLogic::getError());
|
||||
}
|
||||
@@ -121,4 +121,4 @@ class RoleController extends BaseAdminController
|
||||
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,68 @@
|
||||
<?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\enum\AdminTerminalEnum;
|
||||
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请求');
|
||||
}
|
||||
// 专用集团终端只在此入口接受;不扩大普通网页登录的终端白名单。
|
||||
$terminal = $this->request->post('terminal');
|
||||
$groupSession = in_array($terminal, [AdminTerminalEnum::GROUP_IDENTITY, (string) AdminTerminalEnum::GROUP_IDENTITY], true);
|
||||
// verify 场景保留原限流并禁用调试免密;服务仍在账号锁内校验全部参数与当前密码。
|
||||
$params = (new LoginValidate())->post()->goCheck($groupSession ? 'verify' : null);
|
||||
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('已退出登录');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user