提交 cdb0c8f0 编写于 作者: G gongfuxiang

应用名称校验优化

上级 4603845f
...@@ -127,8 +127,19 @@ class Pluginsadmin extends Common ...@@ -127,8 +127,19 @@ class Pluginsadmin extends Common
} }
$this->assign('data', $data); $this->assign('data', $data);
// 名称校验
if(!empty($params['plugins']))
{
$ret = PluginsAdminService::PluginsVerification($params, $params['plugins']);
if($ret['code'] != 0)
{
$this->assign('verification_msg', $ret['msg']);
return $this->fetch('first_step');
}
}
// 标记为空或等于view 并且 编辑数据为空则走第一步 // 标记为空或等于view 并且 编辑数据为空则走第一步
if((empty($params['plugins']) || $params['plugins'] == 'view') && empty($data['data'][0])) if(empty($params['plugins']) && empty($data['data'][0]))
{ {
return $this->fetch('first_step'); return $this->fetch('first_step');
} else { } else {
......
...@@ -19,6 +19,12 @@ ...@@ -19,6 +19,12 @@
<div class="am-form-group"> <div class="am-form-group">
<label>应用唯一标记<span class="am-form-group-label-tips">以数字、字母小写、下划线</span></label> <label>应用唯一标记<span class="am-form-group-label-tips">以数字、字母小写、下划线</span></label>
<input type="text" name="plugins" placeholder="名称" minlength="2" maxlength="60" data-validation-message="应用唯一标记格式 2~60 个字符" pattern="^[a-z0-9_]{2,60}$" class="am-radius" {{if !empty($data)}} value="{{$data.plugins}}"{{/if}} required /> <input type="text" name="plugins" placeholder="名称" minlength="2" maxlength="60" data-validation-message="应用唯一标记格式 2~60 个字符" pattern="^[a-z0-9_]{2,60}$" class="am-radius" {{if !empty($data)}} value="{{$data.plugins}}"{{/if}} required />
<!-- 校验信息 -->
{{if !empty($verification_msg)}}
<div class="am-alert am-alert-danger" data-am-alert>
{{$verification_msg}} , 请重新填写!
</div>
{{/if}}
</div> </div>
<div class="am-form-group am-form-group-refreshing"> <div class="am-form-group am-form-group-refreshing">
......
...@@ -23,6 +23,9 @@ use app\service\SqlconsoleService; ...@@ -23,6 +23,9 @@ use app\service\SqlconsoleService;
*/ */
class PluginsAdminService class PluginsAdminService
{ {
// 排除不能使用的名称
public static $plugins_exclude_verification = ['view', 'shopxo', 'www'];
/** /**
* 列表 * 列表
* @author Devil * @author Devil
...@@ -807,6 +810,33 @@ php; ...@@ -807,6 +810,33 @@ php;
return DataReturn('创建成功', 0); return DataReturn('创建成功', 0);
} }
/**
* 名称校验
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-13T00:00:45+0800
* @param [array] $params [输入参数]
* @param [string] $plugins [应用唯一标记]
*/
public static function PluginsVerification($params, $plugins)
{
// 排除校验
if(in_array($plugins, self::$plugins_exclude_verification))
{
return DataReturn('不能使用限制的名称['.$plugins.']', -1);
}
// 应用是否存在
$temp_plugins = Db::name('Plugins')->where(['plugins'=>$plugins])->value('plugins');
if(empty($params['id']) && $temp_plugins == $plugins)
{
return DataReturn('应用名称已存在['.$plugins.']', -1);
}
return DataReturn('校验成功', 0);
}
/** /**
* 应用添加 * 应用添加
* @author Devil * @author Devil
...@@ -819,13 +849,16 @@ php; ...@@ -819,13 +849,16 @@ php;
*/ */
private static function PluginsExistInsert($params, $plugins) private static function PluginsExistInsert($params, $plugins)
{ {
// 是否非使用的名称 // 名称校验
if(in_array($plugins, ['view', 'shopxo'])) $ret = self::PluginsVerification($params, $plugins);
if($ret['code'] != 0)
{ {
return DataReturn('不能使用限制的名称['.$plugins.']', -1); return $ret;
} }
// 应用是否存在 // 应用添加
if(empty($params['id']))
{
$temp_plugins = Db::name('Plugins')->where(['plugins'=>$plugins])->value('plugins'); $temp_plugins = Db::name('Plugins')->where(['plugins'=>$plugins])->value('plugins');
if(empty($temp_plugins)) if(empty($temp_plugins))
{ {
...@@ -833,12 +866,9 @@ php; ...@@ -833,12 +866,9 @@ php;
{ {
return DataReturn('应用添加失败', -1); return DataReturn('应用添加失败', -1);
} }
} else {
if(empty($params['id']) && $temp_plugins == $plugins)
{
return DataReturn('应用名称已存在['.$plugins.']', -1);
} }
} }
return DataReturn('添加成功', 0); return DataReturn('添加成功', 0);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册