diff --git a/db/update11.5.sql b/db/update11.5.sql new file mode 100644 index 0000000000..3cb2abfd65 --- /dev/null +++ b/db/update11.5.sql @@ -0,0 +1 @@ +ALTER TABLE `zt_entry` ADD `freePasswd` enum('0','1') NOT NULL DEFAULT '0' AFTER `key`; diff --git a/db/zentao.sql b/db/zentao.sql index 046cb8230a..7198cc851b 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -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, diff --git a/module/common/model.php b/module/common/model.php index a6331566c8..5555e27279 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -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); diff --git a/module/entry/config.php b/module/entry/config.php index 98913d48b4..c87c7c1484 100644 --- a/module/entry/config.php +++ b/module/entry/config.php @@ -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; diff --git a/module/entry/js/create.js b/module/entry/js/create.js index abec4ca334..4ca8a8d87c 100644 --- a/module/entry/js/create.js +++ b/module/entry/js/create.js @@ -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'); + } + }) }); diff --git a/module/entry/lang/en.php b/module/entry/lang/en.php index 33d1a0741a..3e28b185c3 100644 --- a/module/entry/lang/en.php +++ b/module/entry/lang/en.php @@ -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'; diff --git a/module/entry/lang/zh-cn.php b/module/entry/lang/zh-cn.php index 092587b9af..30d35df9f0 100644 --- a/module/entry/lang/zh-cn.php +++ b/module/entry/lang/zh-cn.php @@ -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已失效'; diff --git a/module/entry/model.php b/module/entry/model.php index 7aaff645a8..6adf038125 100644 --- a/module/entry/model.php +++ b/module/entry/model.php @@ -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') diff --git a/module/entry/view/create.html.php b/module/entry/view/create.html.php index cdf6fbe532..8ce7b7ba15 100644 --- a/module/entry/view/create.html.php +++ b/module/entry/view/create.html.php @@ -20,7 +20,7 @@ arrow . ' ' . $lang->entry->create;?> -
+ @@ -32,6 +32,11 @@ + + + + + diff --git a/module/webhook/model.php b/module/webhook/model.php index 6097530ace..16eaef5907 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -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);
entry->name;?>entry->note->code}' placeholder='{$lang->entry->note->code}'");?>
entry->freePasswd;?>entry->freePasswdList, "class='form-control'");?>
entry->account;?> entry->note->account}'");?>