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

优化登录状态session中存储为数组格式
优化Auth的isLogin方法只需查询一次数据库
pull/28/head
Karson 2017-12-06 10:13:44 +08:00
parent 65d04fe528
commit 4149fce838
7 changed files with 42 additions and 40 deletions

View File

@ -2,10 +2,10 @@
namespace app\admin\controller\general; namespace app\admin\controller\general;
use think\Session; use app\admin\model\Admin;
use app\admin\model\AdminLog;
use app\common\controller\Backend; use app\common\controller\Backend;
use fast\Random; use fast\Random;
use think\Session;
/** /**
* 个人配置 * 个人配置
@ -64,14 +64,10 @@ class Profile extends Backend
} }
if ($params) if ($params)
{ {
model('admin')->where('id', $this->auth->id)->update($params); $admin = Admin::get($this->auth->id);
$admin->save($params);
//因为个人资料面板读取的Session显示修改自己资料后同时更新Session //因为个人资料面板读取的Session显示修改自己资料后同时更新Session
$admin = Session::get('admin'); Session::set("admin", $admin->toArray());
$admin_id = $admin ? $admin->id : 0;
if($this->auth->id==$admin_id){
$admin = model('admin')->get(['id' => $admin_id]);
Session::set("admin", $admin);
}
$this->success(); $this->success();
} }
$this->error(); $this->error();

View File

@ -1,16 +1,16 @@
<?php <?php
return [ return [
'Toggle all' => '显示全部', 'Toggle all' => '显示全部',
'Condition' => '规则条件', 'Condition' => '规则条件',
'Remark' => '备注', 'Remark' => '备注',
'Icon' => '图标', 'Icon' => '图标',
'Alert' => '警告', 'Alert' => '警告',
'Name' => '规则URL', 'Name' => '规则URL',
'Controller/Action' => '控制器名/方法名', 'Controller/Action' => '控制器名/方法名',
'Ismenu' => '菜单', 'Ismenu' => '菜单',
'Search icon' => '搜索图标', 'Search icon' => '搜索图标',
'The non-menu rule must have parent' => '非菜单规则节点必须有父级', 'The non-menu rule must have parent' => '非菜单规则节点必须有父级',
'If not necessary, use the command line to build rule' => '非必要情况下请直接使用命令行php think menu来生成', 'If not necessary, use the command line to build rule' => '非必要情况下请直接使用命令行php think menu来生成',
'Name only supports letters, numbers, underscore and pipe' => 'URL规则只能是小写字母、数字、下划线和|组成', 'Name only supports letters, numbers, underscore and slash' => 'URL规则只能是小写字母、数字、下划线和/组成',
]; ];

View File

@ -15,6 +15,7 @@ class Auth extends \fast\Auth
protected $requestUri = ''; protected $requestUri = '';
protected $breadcrumb = []; protected $breadcrumb = [];
protected $loginUnique = false; //是否同一账号同一时间只能在一个地方登录 protected $loginUnique = false; //是否同一账号同一时间只能在一个地方登录
protected $logined = false; //登录状态
public function __construct() public function __construct()
{ {
@ -89,7 +90,7 @@ class Auth extends \fast\Auth
{ {
return false; return false;
} }
Session::set("admin", $admin); Session::set("admin", $admin->toArray());
//刷新自动登录的时效 //刷新自动登录的时效
$this->keeplogin($keeptime); $this->keeplogin($keeptime);
return true; return true;
@ -154,6 +155,10 @@ class Auth extends \fast\Auth
*/ */
public function isLogin() public function isLogin()
{ {
if ($this->logined)
{
return true;
}
$admin = Session::get('admin'); $admin = Session::get('admin');
if (!$admin) if (!$admin)
{ {
@ -168,6 +173,7 @@ class Auth extends \fast\Auth
return false; return false;
} }
} }
$this->logined = true;
return true; return true;
} }

View File

@ -2,6 +2,7 @@
namespace app\admin\model; namespace app\admin\model;
use app\admin\library\Auth;
use think\Model; use think\Model;
class AdminLog extends Model class AdminLog extends Model
@ -29,9 +30,9 @@ class AdminLog extends Model
public static function record($title = '') public static function record($title = '')
{ {
$admin = \think\Session::get('admin'); $auth = Auth::instance();
$admin_id = $admin ? $admin->id : 0; $admin_id = $auth->isLogin() ? $auth->id : 0;
$username = $admin ? $admin->username : __('Unknown'); $username = $auth->isLogin() ? $auth->username : __('Unknown');
$content = self::$content; $content = self::$content;
if (!$content) if (!$content)
{ {
@ -48,7 +49,7 @@ class AdminLog extends Model
if (!$title) if (!$title)
{ {
$title = []; $title = [];
$breadcrumb = \app\admin\library\Auth::instance()->getBreadcrumb(); $breadcrumb = Auth::instance()->getBreadcrumb();
foreach ($breadcrumb as $k => $v) foreach ($breadcrumb as $k => $v)
{ {
$title[] = $v['title']; $title[] = $v['title'];

View File

@ -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 = [ protected $message = [
'name.format' => 'URL规则只能是小写字母、数字、下划线和|组成' 'name.format' => 'URL规则只能是小写字母、数字、下划线和/组成'
]; ];
/** /**
@ -45,7 +45,7 @@ class AuthRule extends Validate
'name' => __('Name'), 'name' => __('Name'),
'title' => __('Title'), '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); parent::__construct($rules, $message, $field);
} }

View File

@ -2,7 +2,7 @@
return array ( return array (
'name' => 'FastAdmin', 'name' => 'FastAdmin',
'beian' => '粤ICP备15054802号-4', 'beian' => '',
'cdnurl' => '', 'cdnurl' => '',
'version' => '1.0.1', 'version' => '1.0.1',
'timezone' => 'Asia/Shanghai', 'timezone' => 'Asia/Shanghai',
@ -15,18 +15,18 @@ return array (
'fixedpage' => 'dashboard', 'fixedpage' => 'dashboard',
'categorytype' => 'categorytype' =>
array ( array (
'default' => '默认', 'default' => 'Default',
'page' => '单页', 'page' => 'Page',
'article' => '文章', 'article' => 'Article',
'test' => '测试', 'test' => 'Test',
), ),
'configgroup' => 'configgroup' =>
array ( array (
'basic' => '基础配置', 'basic' => 'Basic',
'email' => '邮件配置', 'email' => 'Email',
'dictionary' => '字典配置', 'dictionary' => 'Dictionary',
'user' => '会员配置', 'user' => 'User',
'example' => '示例分组', 'example' => 'Example',
), ),
'mail_type' => '1', 'mail_type' => '1',
'mail_smtp_host' => 'smtp.qq.com', 'mail_smtp_host' => 'smtp.qq.com',

View File

@ -18,7 +18,6 @@ use think\Db;
use think\Config; use think\Config;
use think\Session; use think\Session;
use think\Request; use think\Request;
use think\Loader;
/** /**
* 权限认证类 * 权限认证类