16 changed files with 1138 additions and 644 deletions
@ -0,0 +1,169 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
|
|||
include_once(dirname(dirname(__FILE__)) . "/library/publicBase.php"); |
|||
include_once(SERVER_ROOT . "/model/mPage.php"); |
|||
|
|||
class admin extends publicBase { |
|||
|
|||
public function login() { |
|||
$name = trim($this->get('name')); |
|||
$password = trim($this->get('password')); |
|||
|
|||
if (!empty($name) && !empty($password)) { |
|||
$m_admin_user = new mAdminUser(); |
|||
$res = $m_admin_user->checkAdminLogin($name, $password); |
|||
if (!$res) $this->show_message($m_admin_user->getError(), '/admin/login'); |
|||
|
|||
header('Location: /admin/formula_list'); |
|||
} |
|||
} |
|||
|
|||
public function user_list() { |
|||
$m_admin_user = new mAdminUser(); |
|||
$list = $m_admin_user->getUserList(); |
|||
|
|||
$this->view['list'] = $list; |
|||
} |
|||
|
|||
public function user_add() {} |
|||
|
|||
public function ajax_save_user() { |
|||
$this->_check_login(true); |
|||
|
|||
$name = trim($this->post('name')); |
|||
$password = md5('123456'); |
|||
|
|||
$m_admin_user = new mAdminUser(); |
|||
$id = $m_admin_user->createUser(array('username' => $name, 'password' => $password)); |
|||
if (!$id) $this->ajax_json(false, '添加失败'); |
|||
|
|||
$this->ajax_json(true, '添加成功'); |
|||
} |
|||
|
|||
public function ajax_update_user() { |
|||
$id = $this->post('id') + 0; |
|||
$data = array( |
|||
'status' => $this->post('status') + 0 |
|||
); |
|||
|
|||
$m_admin_user = new mAdminUser(); |
|||
$id = $m_admin_user->updateUser($id, $data); |
|||
if (!$id) $this->ajax_json(false, '操作失败'); |
|||
|
|||
$this->ajax_json(true, '操作成功'); |
|||
} |
|||
|
|||
public function save_pass() { |
|||
$username = trim($this->get('username')); |
|||
|
|||
$m_admin_user = new mAdminUser(); |
|||
$user = $m_admin_user->getAdminUserByName($username); |
|||
if (!$user) $this->show_message("没有此用户", '/admin/formula_list'); |
|||
|
|||
$this->view['id'] = $user['id']; |
|||
} |
|||
|
|||
public function ajax_save_pass() { |
|||
$id = $this->post('id') + 0; |
|||
$password = trim($this->post('password')); |
|||
if (!$id || !$password) $this->ajax_json(false, '参数错误'); |
|||
|
|||
$uinfo = $this->get_uinfo(); |
|||
if ($uinfo['id'] != $id) $this->ajax_json(false, '用户不存在'); |
|||
|
|||
$m_admin_user = new mAdminUser(); |
|||
$user = $m_admin_user->getAdminUserById($id); |
|||
if (!$user) $this->ajax_json(false, '用户不存在'); |
|||
|
|||
$data = array( |
|||
'password' => md5($password) |
|||
); |
|||
$id = $m_admin_user->updateUser($id, $data); |
|||
if (!$id) $this->ajax_json(false, '操作失败'); |
|||
|
|||
$this->ajax_json(true, '操作成功'); |
|||
} |
|||
|
|||
public function formula_list() { |
|||
$is_all = $this->get('is_all') + 0; |
|||
$status = $this->get('status') + 0; |
|||
$name = trim($this->get('name')); |
|||
|
|||
$condition = array(); |
|||
$url = "/admin/formula_list/is_all/{$is_all}/status/{$status}"; |
|||
if ($name) { |
|||
$condition['name'] = $name; |
|||
$url .= "/name/{$name}"; |
|||
} |
|||
if (!$is_all) { |
|||
$condition['uid'] = 0; |
|||
} |
|||
if ($status == 0) { |
|||
$condition['is_delete'] = array(0, 2); |
|||
} elseif ($status == 1) { |
|||
$condition['is_delete'] = 2; |
|||
} elseif ($status == 2) { |
|||
$condition['is_delete'] = 0; |
|||
} |
|||
|
|||
$mformula = new mFormula(); |
|||
$total = $mformula->getFormulaTotal($condition); |
|||
|
|||
// 分页 |
|||
$page = new Page(); |
|||
$page->setTotalnum($total); |
|||
$page->setUrl($url . '/page/'); |
|||
$curpage = $this->get('page') > 0 ? $this->get('page') : 1; |
|||
$page->setPage($curpage); |
|||
|
|||
$this->view['page_list'] = $page->getPageList(); |
|||
$this->view['curpage'] = $curpage; |
|||
|
|||
if ($curpage > 1) $this->view['prev_page'] = $page->url . ($curpage - 1); //上一页连接 |
|||
if ($curpage < $page->totalpage) $this->view['post_page'] = $page->url . ($curpage + 1); //下一页连接 |
|||
|
|||
//只取出当前页显示 |
|||
$list = $mformula->getFormulaList($condition, $curpage, $page->pagesize); |
|||
|
|||
$this->view['list'] = $list; |
|||
} |
|||
|
|||
public function formula_add() { |
|||
$id = $this->get('id'); |
|||
if ($id) { |
|||
$mformula = new mFormula(); |
|||
$data = $mformula->getFormulaInfo($id, 0); |
|||
|
|||
$this->view['data'] = $data; |
|||
} |
|||
} |
|||
|
|||
public function ajax_save_formula() { |
|||
$id = $this->post('id') + 0; |
|||
$name = trim($this->post('name')); |
|||
$source = trim($this->post('source')); |
|||
$method = trim($this->post('method')); |
|||
$herbs = $this->post('herbs'); |
|||
|
|||
$mformula = new mFormula(); |
|||
$id = $mformula->saveFormula(0, $id, $name, $source, $method, $herbs); |
|||
if (!$id) $this->ajax_json(false, $mformula->getError()); |
|||
|
|||
$this->ajax_json(true, '请求成功', array('id' => $id)); |
|||
} |
|||
|
|||
public function ajax_delete_formula() { |
|||
$id = $this->post('id') + 0; |
|||
$is_delete = $this->post('is_delete') + 0; |
|||
|
|||
$mformula = new mFormula(); |
|||
$id = $mformula->deleteFormula(0, $id, $is_delete); |
|||
if (!$id) $this->ajax_json(false, $mformula->getError()); |
|||
|
|||
$this->ajax_json(true, '请求成功'); |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
<?php |
|||
/** |
|||
* |
|||
*/ |
|||
include_once SERVER_ROOT . '/data/dBase.php'; |
|||
|
|||
class dAdminUser extends dBase { |
|||
protected $fieldlist = array( |
|||
'tcm_admin_user' => array( |
|||
'id', |
|||
'username', |
|||
'password', |
|||
'status', |
|||
'is_super', |
|||
'create_time', |
|||
), |
|||
); |
|||
|
|||
protected $primary_keys = array( |
|||
'tcm_admin_user' => 'id', |
|||
); |
|||
} |
|||
|
@ -0,0 +1,105 @@ |
|||
<?php |
|||
/** |
|||
* |
|||
*/ |
|||
include_once(SERVER_ROOT . "/model/mBase.php"); |
|||
|
|||
|
|||
class mAdminUser extends mBase { |
|||
private $obj; |
|||
private $tbl; |
|||
|
|||
public function __construct() { |
|||
$this->obj = new dAdminUser(); |
|||
$this->tbl = 'tcm_admin_user'; |
|||
} |
|||
|
|||
public function getAdminUserByName($name) { |
|||
return $this->obj->select($this->tbl, array('sql' => '`username`=?', 'vals' => array($name))); |
|||
} |
|||
|
|||
public function getAdminUserById($id) { |
|||
return $this->obj->select($this->tbl, array('sql' => '`id`=?', 'vals' => array($id))); |
|||
} |
|||
|
|||
public function getUserList() { |
|||
return $this->obj->selectAll($this->tbl); |
|||
} |
|||
|
|||
public function createUser($info) { |
|||
return $this->obj->insert($this->tbl, $info); |
|||
} |
|||
|
|||
public function updateUser($id, $info) { |
|||
return $this->obj->update($this->tbl, $info, array('sql' => '`id`=?', 'vals' => array($id))); |
|||
} |
|||
|
|||
public function checkAdminLogin($name, $password) { |
|||
if (empty($name) || empty($password)) { |
|||
$this->setError('参数错误'); |
|||
return false; |
|||
} |
|||
|
|||
$admin_user = $this->getAdminUserByName($name); |
|||
if (empty($admin_user)) { |
|||
$this->setError('用户不存在'); |
|||
return false; |
|||
} |
|||
|
|||
if ($admin_user['password'] !== md5($password)) { |
|||
$this->setError('密码不正确'); |
|||
return false; |
|||
} |
|||
|
|||
if ($admin_user['status'] != 0) { |
|||
$this->setError('用户已禁用'); |
|||
return false; |
|||
} |
|||
|
|||
//设置登录状态 |
|||
setcookie("uid", $admin_user['id'], time() + 3600 * 24, '/'); |
|||
setcookie("token", $this->getToken($admin_user['id']), time() + 3600 * 24, '/'); |
|||
return true; |
|||
} |
|||
|
|||
public function getUserByOpenid($openid) { |
|||
return $this->obj->select($this->tbl, array('sql' => '`openid`=?', 'vals' => array($openid))); |
|||
} |
|||
|
|||
function createUniqueID($openid) { |
|||
$uuid = uniqid($openid, true); |
|||
$hash = hash('sha256', $uuid); |
|||
$decimal = base_convert(substr($hash, 0, 16), 16, 10); |
|||
return substr($decimal, 0, 10); |
|||
} |
|||
|
|||
public function getUserByIdentifier($identifier) { |
|||
return $this->obj->select($this->tbl, array('sql' => '`identifier`=?', 'vals' => array($identifier))); |
|||
} |
|||
|
|||
public function getUserByUid($uid) { |
|||
return $this->obj->select($this->tbl, array('sql' => '`uid`=?', 'vals' => array($uid))); |
|||
} |
|||
|
|||
public function getToken($uid) { |
|||
$secretKey = JWT_KEY; |
|||
$timestamp = time(); |
|||
$data = $uid . '|' . $timestamp; |
|||
$token = hash_hmac('sha256', $data, $secretKey); |
|||
return base64_encode($data . '|' . $token); |
|||
} |
|||
|
|||
public function validateToken($uid, $token) { |
|||
$secretKey = JWT_KEY; |
|||
$decodedToken = base64_decode($token); |
|||
list($valid_uid, $timestamp, $tokenHash) = explode('|', $decodedToken); |
|||
|
|||
$data = $uid . '|' . $timestamp; |
|||
$validToken = hash_hmac('sha256', $data, $secretKey); |
|||
|
|||
if (hash_equals($validToken, $tokenHash) && time() - $timestamp < 7200) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
} |
@ -0,0 +1,118 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery-1.8.1.min.js"></script> |
|||
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery.form.js"></script> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
|||
<title>修改密码</title> |
|||
<meta name="viewport" content="width=device-width,initial-scale=1"> |
|||
<link href="{$smarty.const.CSS_URL}/css/global.css?v={$smarty.const.CSS_JS_VERSION}" media="screen" rel="stylesheet" type="text/css"> |
|||
</head> |
|||
<body> |
|||
|
|||
<div id="page"> |
|||
<div class="container"> |
|||
<section id="main"> |
|||
<div id="main-content"> |
|||
<div class="record-control"> |
|||
<div class="header"> |
|||
<span style="font-size:14px;padding:5px">修改密码</span> |
|||
<div class="row"> </div> |
|||
<div class="flash-message"></div> |
|||
|
|||
<ul class="tabs"><li></li></ul> |
|||
</div> |
|||
</div> |
|||
|
|||
<div id="domain-list"> |
|||
<div class="entry"> |
|||
<div class="modal-body"> |
|||
<div class="wizard-container"><div> |
|||
<div class="inputs"> |
|||
<div id="form_area"> |
|||
<form id="prescription-form" onsubmit="submitForm(event)"> |
|||
<input id="id" name="id" type="hidden" value="{$data.id}"> |
|||
|
|||
<div class="row"> </div> |
|||
|
|||
<div class="row"> |
|||
<label for="name">密码<font color='red'>*</font>:</label> |
|||
<input type="text" id="password" name="password" maxlength="" style="width:280px" value=""> |
|||
</div> |
|||
|
|||
<div class="row"> </div> |
|||
|
|||
<div class="row" id="" style="position:relative;"> |
|||
<label> </label> |
|||
|
|||
<button class="button primary next submitlock" id="submitbtn" onclick="submitForm()"><span class="tdesc_text" style="color:white;">提交</span></button> |
|||
</div> |
|||
|
|||
<div class="row"> </div> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div></div> |
|||
<div style="display: none;" id="formtips"> |
|||
<div class="alert-message block-message info" style="color:red;"></div> |
|||
</div> |
|||
</div> |
|||
<!--end of a domain entry--> |
|||
</div> |
|||
<!-- 批量上传 <div id="onetickupload"></div> --> |
|||
</div> |
|||
</section> |
|||
<!--end of main section--> |
|||
</div><!--end of container--> |
|||
</div><!--end of #page--> |
|||
|
|||
{literal} |
|||
<script type="text/javascript"> |
|||
|
|||
function submitForm() { |
|||
const id = {/literal}{$id}{literal}; |
|||
const password = document.getElementById('password').value; |
|||
const data = { |
|||
id: id, |
|||
password: password, |
|||
}; |
|||
$.ajax({ |
|||
url: '/admin/ajax_save_pass', // 替换为你的服务器端处理文件 |
|||
type: 'POST', |
|||
data: data, |
|||
dataType: 'json', |
|||
success: function (response) { |
|||
alert(response.info); |
|||
if (response.status == true) { |
|||
window.location.href = "/admin/formula_list" |
|||
} |
|||
|
|||
if(response.data.code == 40002){ |
|||
window.location.href = "/admin/login"; |
|||
} |
|||
}, |
|||
error: function (xhr, status, error) { |
|||
console.error('错误:', response); |
|||
alert('提交失败,请重试。'); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
</script> |
|||
<style> |
|||
.add-button { |
|||
width: 20px; |
|||
height: 20px; |
|||
background-color: #DD4B38; |
|||
border: none; |
|||
border-radius: 50px; |
|||
color: #fff; |
|||
} |
|||
</style> |
|||
{/literal} |
|||
|
|||
</body> |
|||
</html> |
@ -0,0 +1,114 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery-1.8.1.min.js"></script> |
|||
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery.form.js"></script> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
|||
<title>添加用户</title> |
|||
<meta name="viewport" content="width=device-width,initial-scale=1"> |
|||
<link href="{$smarty.const.CSS_URL}/css/global.css?v={$smarty.const.CSS_JS_VERSION}" media="screen" rel="stylesheet" type="text/css"> |
|||
</head> |
|||
<body> |
|||
|
|||
<div id="page"> |
|||
<div class="container"> |
|||
<section id="main"> |
|||
<div id="main-content"> |
|||
<div class="record-control"> |
|||
<div class="header"> |
|||
<span style="font-size:14px;padding:5px">添加用户</span> |
|||
<div class="row"> </div> |
|||
<div class="flash-message"></div> |
|||
|
|||
<ul class="tabs"><li></li></ul> |
|||
</div> |
|||
</div> |
|||
|
|||
<div id="domain-list"> |
|||
<div class="entry"> |
|||
<div class="modal-body"> |
|||
<div class="wizard-container"><div> |
|||
<div class="inputs"> |
|||
<div id="form_area"> |
|||
<form id="prescription-form" onsubmit="submitForm(event)"> |
|||
<input id="id" name="id" type="hidden" value="{$data.id}"> |
|||
|
|||
<div class="row"> </div> |
|||
|
|||
<div class="row"> |
|||
<label for="name">用户名<font color='red'>*</font>:</label> |
|||
<input type="text" id="name" name="name" maxlength="" style="width:280px" value=""> |
|||
</div> |
|||
|
|||
<div class="row"> </div> |
|||
|
|||
<div class="row" id="" style="position:relative;"> |
|||
<label> </label> |
|||
|
|||
<button class="button primary next submitlock" id="submitbtn" onclick="submitForm()"><span class="tdesc_text" style="color:white;">提交</span></button> |
|||
</div> |
|||
|
|||
<div class="row"> </div> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div></div> |
|||
<div style="display: none;" id="formtips"> |
|||
<div class="alert-message block-message info" style="color:red;"></div> |
|||
</div> |
|||
</div> |
|||
<!--end of a domain entry--> |
|||
</div> |
|||
<!-- 批量上传 <div id="onetickupload"></div> --> |
|||
</div> |
|||
</section> |
|||
<!--end of main section--> |
|||
</div><!--end of container--> |
|||
</div><!--end of #page--> |
|||
|
|||
{literal} |
|||
<script type="text/javascript"> |
|||
|
|||
function submitForm(e) { |
|||
e.preventDefault(); // 阻止默认表单提交 |
|||
const name = document.getElementById('name').value; |
|||
$.ajax({ |
|||
url: '/admin/ajax_save_user', // 替换为你的服务器端处理文件 |
|||
type: 'POST', |
|||
data: {name:name}, |
|||
dataType: 'json', |
|||
success: function (response) { |
|||
alert(response.info); |
|||
if (response.status == true) { |
|||
window.location.href = "/admin/user_list" |
|||
} |
|||
|
|||
if(response.data.code == 40002){ |
|||
window.location.href = "/admin/login"; |
|||
} |
|||
}, |
|||
error: function (xhr, status, error) { |
|||
console.error('错误:', response); |
|||
alert('提交失败,请重试。'); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
</script> |
|||
<style> |
|||
.add-button { |
|||
width: 20px; |
|||
height: 20px; |
|||
background-color: #DD4B38; |
|||
border: none; |
|||
border-radius: 50px; |
|||
color: #fff; |
|||
} |
|||
</style> |
|||
{/literal} |
|||
|
|||
</body> |
|||
</html> |
@ -0,0 +1,110 @@ |
|||
<!DOCTYPE html> |
|||
<html class="no-js" lang="zh-CN"> |
|||
<head> |
|||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery-1.8.1.min.js"></script> |
|||
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery.form.js"></script> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
|||
<title>管理员列表</title> |
|||
<meta name="viewport" content="width=device-width,initial-scale=1"> |
|||
<link href="{$smarty.const.CSS_URL}/css/global.css?v={$smarty.const.CSS_JS_VERSION}" media="screen" rel="stylesheet" |
|||
type="text/css"> |
|||
</head> |
|||
<body> |
|||
|
|||
<div id="page"> |
|||
<div class="container"> |
|||
<section id="main" style="width: 100%;"> |
|||
<div id="main-content"> |
|||
<div class="record-control"> |
|||
<div class="flash-message"></div> |
|||
<ul class="tabs"> |
|||
<li class="active"><a href="javascript:;">管理员列表</a></li> |
|||
<div style="display:inline-block;float: right;"> |
|||
<button class="button primary next" onclick="to_add()">添加管理员</button> |
|||
</div> |
|||
</ul> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="entry"> |
|||
<div class="modal-body"> |
|||
<table class="table table-striped table-bordered table-condensed"> |
|||
<thead> |
|||
<tr> |
|||
<th width="50">ID</th> |
|||
<th width="50">管理员</th> |
|||
<th width="50">操作</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{foreach from=$list key=key item=item} |
|||
<tr> |
|||
<td>{$item.id}</td> |
|||
<td>{$item.username}</td> |
|||
<td> |
|||
{if $item.is_super == 0} |
|||
{if $item.status == 0} |
|||
<a href="javascript:;" onclick="to_disabled({$item.id},1)">禁用</a> |
|||
{else} |
|||
<a href="javascript:;" onclick="to_disabled({$item.id},0)">启用</a> |
|||
{/if} |
|||
{/if} |
|||
</td> |
|||
</tr> |
|||
{/foreach} |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
|
|||
</div> |
|||
</section><!--end of main section--> |
|||
|
|||
</div><!--end of container--> |
|||
|
|||
</div><!--end of #page--> |
|||
|
|||
{literal} |
|||
<script type="text/javascript"> |
|||
function to_add() { |
|||
location.href = '/admin/user_add'; |
|||
} |
|||
|
|||
function to_disabled(id, status) { |
|||
if (!confirm("确定要禁用吗?")) { |
|||
console.log("用户选择了确认"); |
|||
return false; |
|||
} |
|||
|
|||
const data = { |
|||
id: id, |
|||
status: status, |
|||
}; |
|||
|
|||
$.ajax({ |
|||
url: '/admin/ajax_update_user', // 替换为你的服务器端处理文件 |
|||
type: 'POST', |
|||
data: data, |
|||
dataType: 'json', |
|||
success: function (response) { |
|||
alert(response.info); |
|||
if (response.status == true) { |
|||
window.location.reload(); |
|||
} |
|||
|
|||
if (response.data.code == 40002) { |
|||
window.location.href = "/admin/login"; |
|||
} |
|||
}, |
|||
error: function (xhr, status, error) { |
|||
console.error('错误:', response); |
|||
alert('提交失败,请重试。'); |
|||
} |
|||
}); |
|||
} |
|||
</script> |
|||
{/literal} |
|||
|
|||
</body> |
|||
</html> |
Loading…
Reference in new issue