作者 Karson

修复规则添加正则错误的BUG

优化登录状态session中存储为数组格式
优化Auth的isLogin方法只需查询一次数据库
... ... @@ -2,10 +2,10 @@
namespace app\admin\controller\general;
use think\Session;
use app\admin\model\AdminLog;
use app\admin\model\Admin;
use app\common\controller\Backend;
use fast\Random;
use think\Session;
/**
* 个人配置
... ... @@ -64,14 +64,10 @@ class Profile extends Backend
}
if ($params)
{
model('admin')->where('id', $this->auth->id)->update($params);
$admin = Admin::get($this->auth->id);
$admin->save($params);
//因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
$admin = Session::get('admin');
$admin_id = $admin ? $admin->id : 0;
if($this->auth->id==$admin_id){
$admin = model('admin')->get(['id' => $admin_id]);
Session::set("admin", $admin);
}
Session::set("admin", $admin->toArray());
$this->success();
}
$this->error();
... ...
<?php
return [
'Toggle all' => '显示全部',
'Condition' => '规则条件',
'Remark' => '备注',
'Icon' => '图标',
'Alert' => '警告',
'Name' => '规则URL',
'Controller/Action' => '控制器名/方法名',
'Ismenu' => '菜单',
'Search icon' => '搜索图标',
'The non-menu rule must have parent' => '非菜单规则节点必须有父级',
'If not necessary, use the command line to build rule' => '非必要情况下请直接使用命令行php think menu来生成',
'Name only supports letters, numbers, underscore and pipe' => 'URL规则只能是小写字母、数字、下划线和|组成',
'Toggle all' => '显示全部',
'Condition' => '规则条件',
'Remark' => '备注',
'Icon' => '图标',
'Alert' => '警告',
'Name' => '规则URL',
'Controller/Action' => '控制器名/方法名',
'Ismenu' => '菜单',
'Search icon' => '搜索图标',
'The non-menu rule must have parent' => '非菜单规则节点必须有父级',
'If not necessary, use the command line to build rule' => '非必要情况下请直接使用命令行php think menu来生成',
'Name only supports letters, numbers, underscore and slash' => 'URL规则只能是小写字母、数字、下划线和/组成',
];
... ...
... ... @@ -15,6 +15,7 @@ class Auth extends \fast\Auth
protected $requestUri = '';
protected $breadcrumb = [];
protected $loginUnique = false; //是否同一账号同一时间只能在一个地方登录
protected $logined = false; //登录状态
public function __construct()
{
... ... @@ -89,7 +90,7 @@ class Auth extends \fast\Auth
{
return false;
}
Session::set("admin", $admin);
Session::set("admin", $admin->toArray());
//刷新自动登录的时效
$this->keeplogin($keeptime);
return true;
... ... @@ -154,6 +155,10 @@ class Auth extends \fast\Auth
*/
public function isLogin()
{
if ($this->logined)
{
return true;
}
$admin = Session::get('admin');
if (!$admin)
{
... ... @@ -168,6 +173,7 @@ class Auth extends \fast\Auth
return false;
}
}
$this->logined = true;
return true;
}
... ...
... ... @@ -2,6 +2,7 @@
namespace app\admin\model;
use app\admin\library\Auth;
use think\Model;
class AdminLog extends Model
... ... @@ -29,9 +30,9 @@ class AdminLog extends Model
public static function record($title = '')
{
$admin = \think\Session::get('admin');
$admin_id = $admin ? $admin->id : 0;
$username = $admin ? $admin->username : __('Unknown');
$auth = Auth::instance();
$admin_id = $auth->isLogin() ? $auth->id : 0;
$username = $auth->isLogin() ? $auth->username : __('Unknown');
$content = self::$content;
if (!$content)
{
... ... @@ -48,7 +49,7 @@ class AdminLog extends Model
if (!$title)
{
$title = [];
$breadcrumb = \app\admin\library\Auth::instance()->getBreadcrumb();
$breadcrumb = Auth::instance()->getBreadcrumb();
foreach ($breadcrumb as $k => $v)
{
$title[] = $v['title'];
... ...
... ... @@ -10,7 +10,7 @@ class AuthRule extends Validate
/**
* 正则
*/
protected $regex = ['format' => '[a-z0-9_\|]+'];
protected $regex = ['format' => '[a-z0-9_\/]+'];
/**
* 验证规则
... ... @@ -24,7 +24,7 @@ class AuthRule extends Validate
* 提示消息
*/
protected $message = [
'name.format' => 'URL规则只能是小写字母、数字、下划线和|组成'
'name.format' => 'URL规则只能是小写字母、数字、下划线和/组成'
];
/**
... ... @@ -45,7 +45,7 @@ class AuthRule extends Validate
'name' => __('Name'),
'title' => __('Title'),
];
$this->message['name.format'] = __('Name only supports letters, numbers, underscore and pipe');
$this->message['name.format'] = __('Name only supports letters, numbers, underscore and slash');
parent::__construct($rules, $message, $field);
}
... ...
... ... @@ -2,7 +2,7 @@
return array (
'name' => 'FastAdmin',
'beian' => '粤ICP备15054802号-4',
'beian' => '',
'cdnurl' => '',
'version' => '1.0.1',
'timezone' => 'Asia/Shanghai',
... ... @@ -15,18 +15,18 @@ return array (
'fixedpage' => 'dashboard',
'categorytype' =>
array (
'default' => '默认',
'page' => '单页',
'article' => '文章',
'test' => '测试',
'default' => 'Default',
'page' => 'Page',
'article' => 'Article',
'test' => 'Test',
),
'configgroup' =>
array (
'basic' => '基础配置',
'email' => '邮件配置',
'dictionary' => '字典配置',
'user' => '会员配置',
'example' => '示例分组',
'basic' => 'Basic',
'email' => 'Email',
'dictionary' => 'Dictionary',
'user' => 'User',
'example' => 'Example',
),
'mail_type' => '1',
'mail_smtp_host' => 'smtp.qq.com',
... ...
... ... @@ -18,7 +18,6 @@ use think\Db;
use think\Config;
use think\Session;
use think\Request;
use think\Loader;
/**
* 权限认证类
... ...