tp6更新到最新版本
目录结构调整
This commit is contained in:
62
app/http/middleware/Admin.php
Normal file
62
app/http/middleware/Admin.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\http\middleware;
|
||||
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后台中间件
|
||||
*/
|
||||
class Admin {
|
||||
|
||||
protected $data = [];
|
||||
|
||||
public function handle($request, \Closure $next) {
|
||||
$response = $next($request);
|
||||
|
||||
if (is_array($response->getData())) {
|
||||
$this->data = array_merge($this->data, $response->getData());
|
||||
} else {
|
||||
$this->data = $response->getData();
|
||||
}
|
||||
|
||||
if ($request->isAjax()) {
|
||||
if (isset($this->data['config'])) {
|
||||
unset($this->data['config']);
|
||||
}
|
||||
return json($this->data);
|
||||
} else {
|
||||
return $response->data($this->fetch());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 显示类
|
||||
*/
|
||||
protected function fetch($template = '') {
|
||||
// 使用内置PHP模板引擎渲染模板输出
|
||||
$config = array(
|
||||
'tpl_replace_string' => array(
|
||||
'__static__' => '/static',
|
||||
'__img__' => '/static/admin/images',
|
||||
'__css__' => '/static/admin/css',
|
||||
'__js__' => '/static/admin/js',
|
||||
'__public__' => '/static/admin',
|
||||
),
|
||||
);
|
||||
|
||||
$template = (isset($this->data['template']) && $this->data['template']) ? $this->data['template'] : $template;
|
||||
|
||||
View::config($config);
|
||||
View::assign('sent_version', sent_version);
|
||||
View::assign('config', (isset($this->data['config']) ? $this->data['config'] : []));
|
||||
View::assign((isset($this->data['data']) ? $this->data['data'] : []));
|
||||
return View::fetch($template);
|
||||
}
|
||||
}
|
||||
63
app/http/middleware/AdminAuth.php
Normal file
63
app/http/middleware/AdminAuth.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\http\middleware;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\facade\Session;
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后台中间件
|
||||
*/
|
||||
class AdminAuth {
|
||||
|
||||
protected $data = ['menu' => [], 'meta_title' => ''];
|
||||
|
||||
public function handle($request, \Closure $next) {
|
||||
$user = Session::get('user');
|
||||
|
||||
if (Session::has('user') && $user['uid']) {
|
||||
$request->user = $user;
|
||||
if ($user['uid'] == 1) {
|
||||
$request->isAdmin = true;
|
||||
}
|
||||
|
||||
$this->getMenu($request); //设置菜单
|
||||
return $next($request);
|
||||
} else {
|
||||
return redirect(url('admin.index/login'))->remember();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 显示菜单
|
||||
*/
|
||||
protected function getMenu($request) {
|
||||
$list = [];
|
||||
$current_controller = '/' . str_replace('.', '/', strtolower($request->controller()));
|
||||
$current_url = $current_controller . '/' . strtolower($request->action());
|
||||
$menu = Cache::get('menu');
|
||||
if (!$menu) {
|
||||
$res = (new \app\model\Menu())->where('is_menu', 1)->select();
|
||||
foreach ($res as $key => $item) {
|
||||
$menu[$item['id']] = $item->toArray();
|
||||
}
|
||||
Cache::set('menu', $menu);
|
||||
}
|
||||
foreach ($menu as $key => $value) {
|
||||
if ($request->isAdmin || in_array($value['id'], array())) {
|
||||
$list[$value['id']] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$menuList = list_to_tree($list);
|
||||
$this->data['menu'] = $menuList;
|
||||
View::assign($this->data);
|
||||
}
|
||||
}
|
||||
52
app/http/middleware/Front.php
Normal file
52
app/http/middleware/Front.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\http\middleware;
|
||||
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后台中间件
|
||||
*/
|
||||
class Front {
|
||||
|
||||
protected $data = [];
|
||||
|
||||
public function handle($request, \Closure $next) {
|
||||
$response = $next($request);
|
||||
$this->data = $response->getData();
|
||||
|
||||
if ($request->isAjax()) {
|
||||
return json($this->data);
|
||||
}else{
|
||||
return $response->data($this->fetch());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 显示类
|
||||
*/
|
||||
protected function fetch($template = ''){
|
||||
// 使用内置PHP模板引擎渲染模板输出
|
||||
$config = array(
|
||||
'tpl_replace_string' => array(
|
||||
'__static__' => '/static',
|
||||
'__img__' => '/static/front/images',
|
||||
'__css__' => '/static/front/css',
|
||||
'__js__' => '/static/front/js',
|
||||
'__public__' => '/static/front',
|
||||
)
|
||||
);
|
||||
if (is_string($this->data)) {
|
||||
$this->data = array('data' => $this->data);
|
||||
}
|
||||
View::config($config);
|
||||
View::assign($this->data);
|
||||
return View::engine('Think')->fetch($template);
|
||||
}
|
||||
}
|
||||
49
app/http/middleware/Validate.php
Normal file
49
app/http/middleware/Validate.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\http\middleware;
|
||||
use think\Response;
|
||||
|
||||
class Validate {
|
||||
|
||||
/**
|
||||
* @param \think\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed|\think\response\Json
|
||||
*/
|
||||
public function handle($request, \Closure $next) {
|
||||
//获取当前参数
|
||||
$params = $request->param();
|
||||
//获取访问控制器
|
||||
$controller = strtr(strtolower($request->controller()), '.', '\\');
|
||||
//获取操作名,用于验证场景scene
|
||||
$scene = $request->action();
|
||||
$validate = "app\\http\\validate\\" . $controller;
|
||||
//仅当验证器存在时 进行校验
|
||||
if (class_exists($validate) && $request->isPost()) {
|
||||
$v = new $validate;
|
||||
//仅当存在验证场景才校验
|
||||
if ($v->hasScene($scene)) {
|
||||
//设置当前验证场景
|
||||
$v->scene($scene);
|
||||
if (!$v->check($params)) {
|
||||
//校验不通过则直接返回错误信息
|
||||
$data = array(
|
||||
'msg' => $v->getError(),
|
||||
'code' => 1,
|
||||
'data' => '',
|
||||
'time' => time(),
|
||||
);
|
||||
return Response::create($data, 'json', 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
29
app/http/validate/admin/Index.php
Normal file
29
app/http/validate/admin/Index.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\http\validate\admin;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Index extends Validate {
|
||||
|
||||
protected $rule = [
|
||||
'username' => 'require',
|
||||
'password' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [];
|
||||
|
||||
/**
|
||||
* @title 登录验证
|
||||
*/
|
||||
public function sceneLogin() {
|
||||
return $this->only(['username','password']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user