* Finish task #5804.

This commit is contained in:
Yagami
2019-06-21 14:08:23 +08:00
parent df6b60bd53
commit 7b41c11c32
10 changed files with 41 additions and 4 deletions

1
db/update11.5.sql Normal file
View File

@@ -0,0 +1 @@
ALTER TABLE `zt_entry` ADD `freePasswd` enum('0','1') NOT NULL DEFAULT '0' AFTER `key`;

View File

@@ -898,6 +898,7 @@ CREATE TABLE IF NOT EXISTS `zt_entry` (
`account` varchar(30) NOT NULL DEFAULT '',
`code` varchar(20) NOT NULL,
`key` varchar(32) NOT NULL,
`freePasswd` enum('0','1') NOT NULL DEFAULT '0',
`ip` varchar(100) NOT NULL,
`desc` text NOT NULL,
`createdBy` varchar(30) NOT NULL,

View File

@@ -1658,12 +1658,16 @@ EOD;
$entry = $this->entry->getByCode($this->get->code);
if(!$entry) $this->response('EMPTY_ENTRY');
if(!$entry->key) $this->response('EMPTY_KEY');
if(empty($entry->account)) $this->response('ACCOUNT_UNBOUND');
if(!$this->checkIP($entry->ip)) $this->response('IP_DENIED');
if(!$this->checkEntryToken($entry)) $this->response('INVALID_TOKEN');
if($entry->freePasswd == 0 and empty($entry->account)) $this->response('ACCOUNT_UNBOUND');
if($_GET['f'] == 'user' and strtolower($_GET['m']) == 'apilogin' and $_GET['account'] and $entry->freePasswd) $entry->account = $_GET['account'];
$user = $this->dao->findByAccount($entry->account)->from(TABLE_USER)->fetch();
if(!$user) $this->response('INVALID_ACCOUNT');
$this->loadModel('user');
$user = $this->dao->findByAccount($entry->account)->from(TABLE_USER)->fetch();
$user->rights = $this->user->authorize($user->account);
$user->groups = $this->user->getGroups($user->account);
$user->view = $this->user->grantUserView($user->account, $user->rights['acls']);
@@ -1671,6 +1675,11 @@ EOD;
$this->session->set('user', $user);
$this->app->user = $user;
if($_GET['f'] == 'user' and strtolower($_GET['m']) == 'apilogin' and $_GET['account'] and $entry->freePasswd)
{
die(js::locate($this->config->webRoot));
}
$this->session->set('ENTRY_CODE', $this->get->code);
$this->session->set('VALID_ENTRY', md5(md5($this->get->code) . $this->server->remote_addr));
$this->loadModel('entry')->saveLog($entry->id, $this->server->request_uri);

View File

@@ -18,3 +18,4 @@ $config->entry->errcode['IP_DENIED'] = 403;
$config->entry->errcode['ACCOUNT_UNBOUND'] = 403;
$config->entry->errcode['EMPTY_ENTRY'] = 404;
$config->entry->errcode['CALLED_TIME'] = 405;
$config->entry->errcode['INVALID_ACCOUNT'] = 406;

View File

@@ -32,4 +32,16 @@ $(function()
})
$('#name').focus();
$("input[id^=freePasswd]").change(function()
{
if($(this).val() == 1)
{
$('#account').closest('tr').addClass('hidden');
}
else
{
$('#account').closest('tr').removeClass('hidden');
}
})
});

View File

@@ -45,5 +45,6 @@ $lang->entry->errmsg['INVALID_TOKEN'] = 'Invalid token.';
$lang->entry->errmsg['SESSION_VERIFY_FAILED'] = 'Session verification failed.';
$lang->entry->errmsg['IP_DENIED'] = 'IP is denied.';
$lang->entry->errmsg['ACCOUNT_UNBOUND'] = 'Account is not bound.';
$lang->entry->errmsg['INVALID_ACCOUNT'] = 'Invalid account.';
$lang->entry->errmsg['EMPTY_ENTRY'] = 'Entry does not exist.';
$lang->entry->errmsg['CALLED_TIME'] = 'Token has expired';

View File

@@ -16,6 +16,7 @@ $lang->entry->id = 'ID';
$lang->entry->name = '名称';
$lang->entry->account = '账号';
$lang->entry->code = '代号';
$lang->entry->freePasswd = '免密登录';
$lang->entry->key = '密钥';
$lang->entry->ip = 'IP';
$lang->entry->desc = '描述';
@@ -37,6 +38,9 @@ $lang->entry->note->ip = "允许访问API的应用ip多个ip用逗号隔
$lang->entry->note->allIP = '无限制';
$lang->entry->note->account = '授权应用账号';
$lang->entry->freePasswdList[0] = '关闭';
$lang->entry->freePasswdList[1] = '开启';
$lang->entry->errmsg['PARAM_CODE_MISSING'] = '缺少code参数';
$lang->entry->errmsg['PARAM_TOKEN_MISSING'] = '缺少token参数';
$lang->entry->errmsg['SESSION_CODE_MISSING'] = '缺少session code';
@@ -45,5 +49,6 @@ $lang->entry->errmsg['INVALID_TOKEN'] = '无效的token参数';
$lang->entry->errmsg['SESSION_VERIFY_FAILED'] = 'session验证失败';
$lang->entry->errmsg['IP_DENIED'] = '该IP被限制访问';
$lang->entry->errmsg['ACCOUNT_UNBOUND'] = '未绑定用户';
$lang->entry->errmsg['INVALID_ACCOUNT'] = '用户不存在';
$lang->entry->errmsg['EMPTY_ENTRY'] = '应用不存在';
$lang->entry->errmsg['CALLED_TIME'] = 'Token已失效';

View File

@@ -83,6 +83,8 @@ class entryModel extends model
->remove('allIP')
->get();
if($this->post->freePasswd == 1) $this->config->entry->create->requiredFields = 'name, code, key';
$this->dao->insert(TABLE_ENTRY)->data($entry)
->batchCheck($this->config->entry->create->requiredFields, 'notempty')
->check('code', 'code')

View File

@@ -20,7 +20,7 @@
<small><?php echo $lang->arrow . ' ' . $lang->entry->create;?></small>
</h2>
</div>
<form id='entryForm' method='post' class='ajaxForm'>
<form id='entryForm' method='post' class='form-ajax'>
<table class='table table-form'>
<tr>
<th class='w-80px'><?php echo $lang->entry->name;?></th>
@@ -32,6 +32,11 @@
<td><?php echo html::input('code', '', "class='form-control' title='{$lang->entry->note->code}' placeholder='{$lang->entry->note->code}'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->entry->freePasswd;?></th>
<td><?php echo html::radio('freePasswd', $lang->entry->freePasswdList, "class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->entry->account;?></th>
<td><?php echo html::select("account", $users, '', "class='form-control chosen' data-placeholder='{$lang->entry->note->account}'");?></td>

View File

@@ -86,7 +86,7 @@ class webhookModel extends model
$object->$field = '';
}
$text = zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]";
$text = substr($data->text, 0, strpos($data->text, '(http')) ? substr($data->text, 0, strpos($data->text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]";
$log->action = $text;
$log->actionURL = $this->getViewLink($action->objectType, $action->objectID);