Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yuan1994 committed Nov 9, 2016
1 parent dd56540 commit 51e1256
Show file tree
Hide file tree
Showing 54 changed files with 266 additions and 278 deletions.
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
##tpadmin 是什么?
> 当前版本: v1.2
## tpadmin 是什么?
tpadmin 是一个基于 ThinkPHP5.0 正式版和 Hui.admin v2.5 的管理后台,简化管理后台的开发流程,简化代码的编写,提高代码复用率,同时集成完整的权限管理和其他管理后台中常用的功能

##官方文档
## 官方文档
[http://www.kancloud.cn/yuan1994/tpadmin](http://www.kancloud.cn/yuan1994/tpadmin)

##在线体验
[http://tpadmin.demo.tianpian.net.cn](http://tpadmin.demo.tianpian.net.cn)
## 在线体验
[http://tpadmin.yuan1994.com](http://tpadmin.yuan1994.com)

默认管理员帐号:admin,默认管理员密码:123456

tpadmin 官方交流群:518162472

##仓库地址
## 仓库地址
[https://github.com/yuan1994/tpadmin](https://github.com/yuan1994/tpadmin)

##使用方法
###git克隆:
git clone [email protected]:yuan1994/tpadmin.git
###直接下载:
## 使用方法

### composer安装
composer create-project yuan1994/tpadmin tpadmin --prefer-dist

### git克隆:
git clone https://github.com/yuan1994/tpadmin
### 直接下载:
https://github.com/yuan1994/tpadmin/archive/master.zip
> 框架的依赖需要通过 composer 下载,请在框架根目录执行 composer update ,已确保依赖的类库能下载下来
##特性
###后端
* 模板、控制器、模型、验证器、数据表自动生成
## 部署
参考 [ThinkPHP5 - 部署](http://www.kancloud.cn/manual/thinkphp5/129745)

部署成功后,建立新建数据库 tpadmin,导入项目根目录的 tpadmin.sql 文件,默认管理员帐号:admin,默认管理员密码:123456,然后访问 http://your-tpadmin-root-domain/admin(都已开启伪静态模式)

## 特性
### 后端
* 模板、控制器、模型、验证器代码、数据表自动生成
* 根据数据库字段生成相应 CURD 模型
* 支持终端生成代码、查看数据库信息,并且支持浏览器模拟终端功能
* RBAC 权限管理
* 完美支持多级控制器及多级控制器权限管理
* 支持前置方法 before
* 支持前置方法 before 和 黑名单方法拦截器
* 支持模板主题
* 节点自动扫描与添加
* 七牛上传及与百度编辑器 (Ueditor) 结合使用
Expand All @@ -36,7 +49,7 @@ https://github.com/yuan1994/tpadmin/archive/master.zip
* 网站操作日志记录(自动水平分表)
* 图片上传管理及回调

###前端
### 前端
* 表单校验
* 无限层级菜单,完美与后端多级控制器兼容
* 自动面包屑导航
Expand All @@ -50,7 +63,7 @@ https://github.com/yuan1994/tpadmin/archive/master.zip
* 二维码生成


##鸣谢:
## 鸣谢:
本平台使用了如下框架或插件、源码
* ThinkPHP 5.0正式版
* Hui.admin v2.5
Expand All @@ -61,5 +74,5 @@ https://github.com/yuan1994/tpadmin/archive/master.zip

>非常感谢这些框架、插件的支持
##License
## License
Apache 2.0
9 changes: 5 additions & 4 deletions application/admin/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct()
}

// 前置方法
$beforeAction = "before" . ucfirst($this->request->action());
$beforeAction = "before" . $this->request->action();
if (method_exists($this, $beforeAction)) {
$this->$beforeAction();
}
Expand Down Expand Up @@ -90,11 +90,12 @@ protected function search($model)
*/
protected function getModel($controller = '')
{
$module = $this->request->module();
if (!$controller) {
$controller = $this->request->controller();
}
if (class_exists("\\app\\admin\\model\\" . $this->parseClass($controller))) {
return Loader::model($this->parseClass($controller));
if (class_exists(Loader::parseClass($module, 'model', $controller))) {
return Loader::model($controller);
} else {
return Db::name($this->parseTable($controller));
}
Expand Down Expand Up @@ -124,7 +125,7 @@ protected function getRealController($controller = '')
* @param string $pk 主键,默认为主键
* @param string $input 接收参数,默认为主键
*/
protected function update($field, $value, $msg = "操作成功", $pk = "", $input = "")
protected function updateField($field, $value, $msg = "操作成功", $pk = "", $input = "")
{
$model = $this->getModel();
if (!$pk) {
Expand Down
19 changes: 12 additions & 7 deletions application/admin/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
/**
* tpAdmin [a web admin based ThinkPHP5]
*
* @author yuan1994 <[email protected]>
* @link http://tpadmin.yuan1994.com/
* @author yuan1994 <[email protected]>
* @link http://tpadmin.yuan1994.com/
* @copyright 2016 yuan1994 all rights reserved.
* @license http://www.apache.org/licenses/LICENSE-2.0
* @license http://www.apache.org/licenses/LICENSE-2.0
*/

use \think\Request;

$basename = Request::instance()->root();
if (pathinfo($basename, PATHINFO_EXTENSION) == 'php') {
$basename = dirname($basename);
}

return [
// 模板参数替换
'view_replace_str' => [
'__ROOT__' => Request::instance()->root(),
'__STATIC__' => Request::instance()->root() . '/static/admin',
'__LIB__' => Request::instance()->root() . '/static/admin/lib',
'__ROOT__' => $basename,
'__STATIC__' => $basename . '/static/admin',
'__LIB__' => $basename . '/static/admin/lib',
],

// traits 目录
'traits_path' => APP_PATH . 'admin' . DS . 'traits' . DS,
'traits_path' => APP_PATH . 'admin' . DS . 'traits' . DS,

// 异常处理 handle 类 留空使用 \think\exception\Handle
'exception_handle' => '\\TpException',
Expand Down
14 changes: 8 additions & 6 deletions application/admin/controller/AdminGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* tpAdmin [a web admin based ThinkPHP5]
*
* @author yuan1994 <[email protected]>
* @link http://tpadmin.yuan1994.com/
* @author yuan1994 <[email protected]>
* @link http://tpadmin.yuan1994.com/
* @copyright 2016 yuan1994 all rights reserved.
* @license http://www.apache.org/licenses/LICENSE-2.0
* @license http://www.apache.org/licenses/LICENSE-2.0
*/

//------------------------
Expand All @@ -14,19 +14,21 @@

namespace app\admin\controller;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);
\think\Loader::import('controller/Controller', \think\Config::get('traits_path'), EXT);

use app\admin\Controller;

class AdminGroup extends Controller
{
use \app\admin\traits\controller\Controller;

protected static $blacklist = ['recyclebin', 'delete', 'recycle', 'deleteforever', 'clear'];
protected static $blacklist = ['deleteforever', 'clear'];

protected function filter(&$map)
{
if ($this->request->param('name')) $map['name'] = ["like", "%" . $this->request->param('name') . "%"];
if ($this->request->param('name')) {
$map['name'] = ["like", "%" . $this->request->param('name') . "%"];
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions application/admin/controller/AdminNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ protected function filter(&$map)
$map['pid'] = $this->request->param('pid', 0);
}

if ($this->request->param('title')) $map['title'] = ["like", "%" . $this->request->param('title') . "%"];
if ($this->request->param('name')) $map['name'] = ["like", "%" . $this->request->param('name') . "%"];
if ($this->request->param('title')) {
$map['title'] = ["like", "%" . $this->request->param('title') . "%"];
}
if ($this->request->param('name')) {
$map['name'] = ["like", "%" . $this->request->param('name') . "%"];
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions application/admin/controller/AdminNodeLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class AdminNodeLoad extends Controller

protected function filter(&$map)
{
if ($this->request->param('title')) $map['title'] = ["like", "%" . $this->request->param('title') . "%"];
if ($this->request->param('name')) $map['name'] = ["like", "%" . $this->request->param('name') . "%"];
if ($this->request->param('title')) {
$map['title'] = ["like", "%" . $this->request->param('title') . "%"];
}
if ($this->request->param('name')) {
$map['name'] = ["like", "%" . $this->request->param('name') . "%"];
}
}
}
4 changes: 3 additions & 1 deletion application/admin/controller/AdminRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class AdminRole extends Controller

protected function filter(&$map)
{
if ($this->request->param('name')) $map['name'] = ["like", "%" . $this->request->param('name') . "%"];
if ($this->request->param('name')) {
$map['name'] = ["like", "%" . $this->request->param('name') . "%"];
}
}

/**
Expand Down
16 changes: 12 additions & 4 deletions application/admin/controller/AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ protected function filter(&$map)
//不查询管理员
$map['id'] = ["gt", 1];

if ($this->request->param('realname')) $map['realname'] = ["like", "%" . $this->request->param('realname') . "%"];
if ($this->request->param('account')) $map['realname'] = ["like", "%" . $this->request->param('account') . "%"];
if ($this->request->param('email')) $map['realname'] = ["like", "%" . $this->request->param('email') . "%"];
if ($this->request->param('mobile')) $map['realname'] = ["like", "%" . $this->request->param('mobile') . "%"];
if ($this->request->param('realname')) {
$map['realname'] = ["like", "%" . $this->request->param('realname') . "%"];
}
if ($this->request->param('account')) {
$map['realname'] = ["like", "%" . $this->request->param('account') . "%"];
}
if ($this->request->param('email')) {
$map['realname'] = ["like", "%" . $this->request->param('email') . "%"];
}
if ($this->request->param('mobile')) {
$map['realname'] = ["like", "%" . $this->request->param('mobile') . "%"];
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions application/admin/controller/LoginLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ protected function filter(&$map)
}

// 关联筛选
if ($this->request->param('account')) $map['admin_user.account'] = $this->request->param('account');
if ($this->request->param('name')) $map['admin_user.realname'] = ["like", "%" . $this->request->param('name') . "%"];
if ($this->request->param('account')) {
$map['admin_user.account'] = $this->request->param('account');
}
if ($this->request->param('name')) {
$map['admin_user.realname'] = ["like", "%" . $this->request->param('name') . "%"];
}

// 设置属性
$map['_table'] = "login_log";
Expand Down
8 changes: 6 additions & 2 deletions application/admin/controller/NodeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class NodeMap extends Controller

protected function filter(&$map)
{
if ($this->request->param("map")) $map['map'] = ["like", "%" . $this->request->param("map") . "%"];
if ($this->request->param("comment")) $map['comment'] = ["like", "%" . $this->request->param("comment") . "%"];
if ($this->request->param("map")) {
$map['map'] = ["like", "%" . $this->request->param("map") . "%"];
}
if ($this->request->param("comment")) {
$map['comment'] = ["like", "%" . $this->request->param("comment") . "%"];
}
}

/**
Expand Down
28 changes: 14 additions & 14 deletions application/admin/controller/Pub.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class Pub
// Request实例
protected $request;

// 黑名单方法,禁止访问某

public function __construct()
{
if (null === $this->view) {
Expand All @@ -44,7 +42,7 @@ public function __construct()
$this->request = Request::instance();
}

//用户ID
// 用户ID
defined('UID') or define('UID', Session::get(Config::get('rbac.user_auth_key')));
}

Expand Down Expand Up @@ -91,7 +89,7 @@ public function loginFrame()
*/
public function index()
{
//如果通过认证跳转到首页
// 如果通过认证跳转到首页
$this->redirect("Index/index");
}

Expand Down Expand Up @@ -125,33 +123,33 @@ public function checkLogin()
$map['status'] = 1;
$auth_info = \Rbac::authenticate($map);

//使用用户名、密码和状态的方式进行认证
// 使用用户名、密码和状态的方式进行认证
if (null === $auth_info) {
return ajax_return_adv_error('帐号不存在或已禁用!');
} else {
if ($auth_info['password'] != password_hash_tp($data['password'])) {
return ajax_return_adv_error('密码错误!');
}

//生成session信息
// 生成session信息
Session::set(Config::get('rbac.user_auth_key'), $auth_info['id']);
Session::set('user_name', $auth_info['account']);
Session::set('real_name', $auth_info['realname']);
Session::set('last_login_ip', $auth_info['last_login_ip']);
Session::set('last_login_time', $auth_info['last_login_time']);

//超级管理员标记
// 超级管理员标记
if ($auth_info['id'] == 1) {
Session::set(Config::get('rbac.admin_auth_key'), true);
}

//保存登录信息
// 保存登录信息
$update['last_login_time'] = time();
$update['login_count'] = ['exp', 'login_count+1'];
$update['last_login_ip'] = $this->request->ip();
Db::name("AdminUser")->where('id', $auth_info['id'])->update($update);

//记录登录日志
// 记录登录日志
$log['uid'] = $auth_info['id'];
$log['login_ip'] = $this->request->ip();
$log['login_location'] = implode(" ", \Ip::find($log['login_ip']));
Expand All @@ -177,19 +175,19 @@ public function password()
$this->checkUser();
if ($this->request->isPost()) {
$data = $this->request->post();
//数据校验
// 数据校验
$validate = Loader::validate('Pub');
if (!$validate->scene('password')->check($data)) {
return ajax_return_adv_error($validate->getError());
}

//查询旧密码进行比对
// 查询旧密码进行比对
$info = Db::name("AdminUser")->where("id", UID)->field("password")->find();
if ($info['password'] != password_hash_tp($data['oldpassword'])) {
return ajax_return_adv_error("旧密码错误");
}

//写入新密码
// 写入新密码
if (false === Loader::model('AdminUser')->updatePassword(UID, $data['password'])) {
return ajax_return_adv_error("密码修改失败");
}
Expand All @@ -206,14 +204,16 @@ public function password()
public function profile()
{
$this->checkUser();
if ($this->request->isPost()) { //修改资料
if ($this->request->isPost()) {
// 修改资料
$data = $this->request->only(['realname', 'email', 'mobile', 'remark'], 'post');
if (Db::name("AdminUser")->where("id", UID)->update($data) === false) {
return ajax_return_adv_error("信息修改失败");
}

return ajax_return_adv("信息修改成功", '');
} else { //查看用户信息
} else {
// 查看用户信息
$vo = Db::name("AdminUser")->field('realname,email,mobile,remark')->where("id", UID)->find();
$this->view->assign('vo', $vo);

Expand Down
Loading

0 comments on commit 51e1256

Please sign in to comment.