webman迁移
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace app\admin\controller;
|
||||
|
||||
use ba\ClickCaptcha;
|
||||
use ba\Random;
|
||||
use app\common\facade\Token;
|
||||
use app\admin\model\AdminLog;
|
||||
use app\common\controller\Backend;
|
||||
@@ -107,8 +108,14 @@ class Index extends Backend
|
||||
|
||||
$res = $this->auth->login($username, $password, (bool) $keep);
|
||||
if ($res === true) {
|
||||
$userInfo = $this->auth->getInfo();
|
||||
// 兜底:若 getInfo 未返回 token,在控制器层生成并入库
|
||||
if (empty($userInfo['token']) && $this->auth->isLogin()) {
|
||||
$userInfo['token'] = Random::uuid();
|
||||
Token::set($userInfo['token'], \app\admin\library\Auth::TOKEN_TYPE, $this->auth->id, (int) config('buildadmin.admin_token_keep_time', 86400 * 3));
|
||||
}
|
||||
return $this->success(__('Login succeeded!'), [
|
||||
'userInfo' => $this->auth->getInfo()
|
||||
'userInfo' => $userInfo
|
||||
]);
|
||||
}
|
||||
$msg = $this->auth->getError();
|
||||
|
||||
@@ -222,8 +222,19 @@ class Auth extends \ba\Auth
|
||||
}
|
||||
$info = $this->model->toArray();
|
||||
$info = array_intersect_key($info, array_flip($this->getAllowFields()));
|
||||
$info['token'] = $this->getToken();
|
||||
$info['refresh_token'] = $this->getRefreshToken();
|
||||
// 与 ThinkPHP 一致:token 为主认证令牌,refresh_token 仅 keep=true 时有值
|
||||
$token = $this->token;
|
||||
if (!$token && $this->loginEd) {
|
||||
$token = Random::uuid();
|
||||
Token::set($token, self::TOKEN_TYPE, $this->model->id, $this->keepTime);
|
||||
$this->token = $token;
|
||||
}
|
||||
$info['token'] = $token ?: '';
|
||||
$info['refresh_token'] = $this->refreshToken ?: '';
|
||||
// last_login_time 与 ThinkPHP 一致返回整数时间戳
|
||||
if (isset($info['last_login_time'])) {
|
||||
$info['last_login_time'] = (int) $info['last_login_time'];
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
public function get{%field%}Attr($value, $row): string
|
||||
{
|
||||
if ($row['{%originalFieldName%}'] === '' || $row['{%originalFieldName%}'] === null) return '';
|
||||
$cityNames = \think\facade\Db::name('area')->whereIn('id', $row['{%originalFieldName%}'])->column('name');
|
||||
$cityNames = \support\think\Db::name('area')->whereIn('id', $row['{%originalFieldName%}'])->column('name');
|
||||
return $cityNames ? implode(',', $cityNames) : '';
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace {%namespace%};
|
||||
|
||||
use think\Model;
|
||||
use support\think\Model;
|
||||
|
||||
/**
|
||||
* {%className%}
|
||||
|
||||
@@ -47,7 +47,7 @@ class AdminLog extends Model
|
||||
}
|
||||
|
||||
/** 设置日志内容(BuildAdmin 控制器调用) */
|
||||
public function setData(string|array $data): void
|
||||
public function setLogData(string|array $data): void
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user