buildadmin/app/common/controller/Backend.php

76 lines
1.9 KiB
PHP
Raw Normal View History

2022-02-24 17:44:00 +00:00
<?php
namespace app\common\controller;
use app\admin\library\Auth;
use think\facade\Cookie;
2022-02-24 17:44:00 +00:00
class Backend extends Api
{
protected $noNeedLogin = [];
protected $noNeedPermission = [];
protected $preExcludeFields = [];
2022-02-24 17:44:00 +00:00
2022-02-26 20:55:27 +00:00
/**
* 权限类实例
* @var Auth
*/
2022-02-24 17:44:00 +00:00
protected $auth = null;
protected $model = null;
2022-03-10 14:50:16 +00:00
/**
* 权重(排序)字段
*/
protected $weighField = 'weigh';
/**
* 表格拖拽排序时,两个权重相等则自动重新整理
* config/buildadmin.php文件中的auto_sort_eq_weight为默认值
* null=取默认值,false=,true=
*/
protected $autoSortEqWeight = null;
/**
* 快速搜索字段
*/
protected $quickSearchField = 'id';
/**
* 引入traits
* traits内实现了index、add、edit等方法
*/
use \app\admin\library\traits\Backend;
public function initialize()
{
parent::initialize();
$this->auth = Auth::instance();
$routePath = $this->controllerPath . '/' . $this->request->action(true);
2022-02-26 20:55:27 +00:00
$token = $this->request->server('HTTP_BATOKEN', $this->request->request('batoken', Cookie::get('batoken') ?: false));
if (!$this->auth->actionInArr($this->noNeedLogin)) {
$this->auth->init($token);
if (!$this->auth->isLogin()) {
$this->error(__('Please login first'), [
2022-02-28 20:54:57 +00:00
'routeName' => 'adminLogin'
], 302);
}
if (!$this->auth->actionInArr($this->noNeedPermission)) {
if (!$this->auth->check($routePath)) {
$this->error(__('You have no permission'), [
'routeName' => 'admin'
2022-02-28 20:54:57 +00:00
], 302);
}
}
} else {
if ($token) {
$this->auth->init($token);
}
}
}
2022-03-08 08:31:49 +00:00
public function select()
{
}
2022-02-24 17:44:00 +00:00
}